A bug causes the download counter for file attachments to reset to zero whenever a post is edited, even after updating to newer versions like v2.1.0.beta1. elsantodel90 first reported the issue after upgrading to v1.9.0.beta13, confirming it persists across browsers. codinghorror verified the bug by editing a post with an attachment and observing the counter reset. zogstrip investigated and found the issue stems from links being re-extracted and recreated during post processing, losing click counts. A fix was implemented to store upload links using the database URL (commit), but it initially didn’t account for CDN URLs. A second fix addressed this (commit). The fix applies only to new posts; old posts require a rebake (with associated click count loss). codinghorror tested the fix by rebaking a post and adding a new attachment, confirming the counter now persists after edits.
So the issue is that we extract links from post several times during the cooking and post cooking process. Since they also change from relative/bare to absolute/cdn in the same process, we’re effectively deleting the links to recreate them later on. Thus losing the clicks count.
I’ve pushed a fix to ensure we always store links to uploads using the URL we keep in the database.
Turns out, I also needed to take into account CDN so I extracted the cook_url method from the CookedPostProcessor and used it so we store the same links as the one we cook in the posts