# Attachment "number of downloads" counter resets whenever a reply is edited

**URL:** https://meta.discourse.org/t/attachment-number-of-downloads-counter-resets-whenever-a-reply-is-edited/72551
**Category:** Bug
**Tags:** click-counter
**Created:** [22.Октябрь.2017 00:50:44 UTC](https://meta.discourse.org/t/attachment-number-of-downloads-counter-resets-whenever-a-reply-is-edited/72551 "2017-10-22T00:50:44Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![elsantodel90](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/elsantodel90/32/119906_2.png) [@elsantodel90](https://meta.discourse.org/u/elsantodel90)
#### Post date: [22.Октябрь.2017 00:50:44 UTC](https://meta.discourse.org/t/attachment-number-of-downloads-counter-resets-whenever-a-reply-is-edited/72551/1 "2017-10-22T00:50:44Z")

</div>

This happens after updating to v1.9.0.beta13 +63

Steps to reproduce:

1. Create a post with attachments.
2. Let some users download them, so that the counters go up.
3. Edit the post, for example adding a single text line at the end.

After this, counters are back to zero.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [22.Октябрь.2017 00:54:17 UTC](https://meta.discourse.org/t/attachment-number-of-downloads-counter-resets-whenever-a-reply-is-edited/72551/2 "2017-10-22T00:54:17Z")

</div>

Does this persist after you refresh the page by pressing f5 in your browser or the refresh button?

---

<div class="post-metadata">

### Author: ![elsantodel90](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/elsantodel90/32/119906_2.png) [@elsantodel90](https://meta.discourse.org/u/elsantodel90)
#### Post date: [22.Октябрь.2017 01:28:37 UTC](https://meta.discourse.org/t/attachment-number-of-downloads-counter-resets-whenever-a-reply-is-edited/72551/3 "2017-10-22T01:28:37Z")

</div>

Yes, it does.

Also using different browsers (chrome and firefox) show the same numbers, which go back to zero for attachments if the reply is edited.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [22.Октябрь.2017 03:02:52 UTC](https://meta.discourse.org/t/attachment-number-of-downloads-counter-resets-whenever-a-reply-is-edited/72551/4 "2017-10-22T03:02:52Z")

</div>

Ok @zogstrip can you take a look next week and see what you think?

---

<div class="post-metadata">

### Author: ![elsantodel90](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/elsantodel90/32/119906_2.png) [@elsantodel90](https://meta.discourse.org/u/elsantodel90)
#### Post date: [01.Июнь.2018 01:51:20 UTC](https://meta.discourse.org/t/attachment-number-of-downloads-counter-resets-whenever-a-reply-is-edited/72551/10 "2018-06-01T01:51:20Z")

</div>

I have just updated to

v2.1.0.beta1 +1

The “link click counter” bug for **file attachments** still remains exactly the same as described.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [01.Июнь.2018 02:11:01 UTC](https://meta.discourse.org/t/attachment-number-of-downloads-counter-resets-whenever-a-reply-is-edited/72551/11 "2018-06-01T02:11:01Z")

</div>

Let’s see

[test-text-file.txt](https://global.discourse-cdn.com/meta/original/3X/8/f/8f93542443e98f41fe98e97d6d2a147193b1b005.txt) (9 Bytes)

I just made an edit to this post, here’s what it looked like before my edit:

 ![image](https://global.discourse-cdn.com/meta/original/3X/9/5/95caccb7d36eec36a0eafbf4c371c4c96faf9ff9.png)

Yep confirmed that resets the count for some reason..

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [09.Июль.2018 08:29:37 UTC](https://meta.discourse.org/t/attachment-number-of-downloads-counter-resets-whenever-a-reply-is-edited/72551/12 "2018-07-09T08:29:37Z")

</div>

This is not as easy as I’d hoped but it’s still on my 📝 list. Will get it fixed by the end of the week.

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [03.Август.2018 23:37:55 UTC](https://meta.discourse.org/t/attachment-number-of-downloads-counter-resets-whenever-a-reply-is-edited/72551/13 "2018-08-03T23:37:55Z")

</div>

So the issue is that we [extract links](https://github.com/discourse/discourse/blob/bf4d98e89d91df4b35bd2c1cc2c17630dbc0f3c3/app/models/topic_link.rb#L111-L254) 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.

[https://github.com/discourse/discourse/commit/bf4d98e89d91df4b35bd2c1cc2c17630dbc0f3c3](https://github.com/discourse/discourse/commit/bf4d98e89d91df4b35bd2c1cc2c17630dbc0f3c3)

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [03.Август.2018 23:40:41 UTC](https://meta.discourse.org/t/attachment-number-of-downloads-counter-resets-whenever-a-reply-is-edited/72551/14 "2018-08-03T23:40:41Z")

</div>

Sounds good but I am a bit unclear. Will this fix all posts or just new posts?

It is OK if it is new posts only, I’m just asking.

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [03.Август.2018 23:43:58 UTC](https://meta.discourse.org/t/attachment-number-of-downloads-counter-resets-whenever-a-reply-is-edited/72551/15 "2018-08-03T23:43:58Z")

</div>

Old posts will require a rebake (and a click count loss), new posts will be 👌.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [07.Август.2018 04:49:34 UTC](https://meta.discourse.org/t/attachment-number-of-downloads-counter-resets-whenever-a-reply-is-edited/72551/16 "2018-08-07T04:49:34Z")

</div>

I rebaked the post above and it doesn’t seem to be working. Let me try a new attachment.

Can everyone reading this please click ↓ ↓

[another-test-file.txt](https://global.discourse-cdn.com/meta/original/3X/2/d/2d2c7f6be6c89784b866fe723996bde0c49c91dd.txt) (19 Bytes)

Post edited, October 3rd 2018!

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [14.Август.2018 10:25:22 UTC](https://meta.discourse.org/t/attachment-number-of-downloads-counter-resets-whenever-a-reply-is-edited/72551/17 "2018-08-14T10:25:22Z")

</div>

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

[https://github.com/discourse/discourse/commit/de92913bf4761939ed5d8162db8337ffc7c8a00b](https://github.com/discourse/discourse/commit/de92913bf4761939ed5d8162db8337ffc7c8a00b)

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [14.Август.2018 16:00:18 UTC](https://meta.discourse.org/t/attachment-number-of-downloads-counter-resets-whenever-a-reply-is-edited/72551/18 "2018-08-14T16:00:18Z")

</div>

This topic was automatically closed after 2 hours. New replies are no longer allowed.
