# Badge notifications not being sent for newly created badges that are retroactive?

**URL:** https://meta.discourse.org/t/badge-notifications-not-being-sent-for-newly-created-badges-that-are-retroactive/25426
**Category:** Bug
**Created:** [2015年二月19日 20:56 UTC](https://meta.discourse.org/t/badge-notifications-not-being-sent-for-newly-created-badges-that-are-retroactive/25426 "2015-02-19T20:56:46Z")
**Posts on this page:** 15
**Page:** 1

<div class="post-metadata">

### Author: ![DeanMarkTaylor](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/deanmarktaylor/32/102462_2.png) [@DeanMarkTaylor](https://meta.discourse.org/u/DeanMarkTaylor)
#### Post date: [2015年二月19日 20:56 UTC](https://meta.discourse.org/t/badge-notifications-not-being-sent-for-newly-created-badges-that-are-retroactive/25426/1 "2015-02-19T20:56:46Z")

</div>

Having a look at my badges here on meta…  
… there are some here I don’t believe I have never received a notification for.

I thought the whole idea for badges was to enforce good behaviour so would think I would get notifications.

![](https://global.discourse-cdn.com/meta/original/3X/5/3/534a23cc07f6ab1c69fd90a6f565764190c60b72.png)

The ones highlighted I really can’t remember receiving ever, there are others too - but these are ones these can be quite sure of.

I can’t see any badge notifications - in my notifications - but I’m not sure I should see them there:

> **[@DeanMarkTaylor](https://meta.discourse.org/users/deanmarktaylor/notifications)**
>
> A busy web developer.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [2015年二月19日 21:32 UTC](https://meta.discourse.org/t/badge-notifications-not-being-sent-for-newly-created-badges-that-are-retroactive/25426/2 "2015-02-19T21:32:46Z")

</div>

Anniversary was just changed to silver so new installs will get it, there is some notification suppression logic see:

> <https://github.com/discourse/discourse/blob/main/app/services/badge_granter.rb#L288>

So its legit that you are not being notified for that.

The sharing badge may need a tweak, its grabbing min(id) instead of max which means it is unlikely to hit the threshold

```plaintext
    SELECT views.user_id, i2.post_id, i2.created_at granted_at
    FROM
    (
      SELECT i.user_id, MIN(i.id) i_id
      FROM incoming_links i
      JOIN badge_posts p on p.id = i.post_id
      WHERE i.user_id IS NOT NULL
      GROUP BY i.user_id,i.post_id
      HAVING COUNT(*) > 25
    ) as views
    JOIN incoming_links i2 ON i2.id = views.i_id

```

---

<div class="post-metadata">

### Author: ![DeanMarkTaylor](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/deanmarktaylor/32/102462_2.png) [@DeanMarkTaylor](https://meta.discourse.org/u/DeanMarkTaylor)
#### Post date: [2015年二月19日 22:53 UTC](https://meta.discourse.org/t/badge-notifications-not-being-sent-for-newly-created-badges-that-are-retroactive/25426/3 "2015-02-19T22:53:11Z")

</div>

> [@sam](#):
>
> Anniversary was just changed to silver so new installs will get it

How will the Anniversary Badge be handled for forums that are 11+ years old?  
11 notifications the first time the badge runs?

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [2015年二月19日 22:53 UTC](https://meta.discourse.org/t/badge-notifications-not-being-sent-for-newly-created-badges-that-are-retroactive/25426/4 "2015-02-19T22:53:51Z")

</div>

at the moment its a once off badge, eventually we want to get a badge ber year but the query needs some careful planning

---

<div class="post-metadata">

### Author: ![riking](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/riking/32/170938_2.png) [@riking](https://meta.discourse.org/u/riking)
#### Post date: [2015年二月20日 00:18 UTC](https://meta.discourse.org/t/badge-notifications-not-being-sent-for-newly-created-badges-that-are-retroactive/25426/5 "2015-02-20T00:18:27Z")

</div>

One possibility would be to add another return column to the badge queries, call it `repeat_id`. Could be trivially mapped to the `seq` column in the badge\_users table. Then have `repeat_id * TIMESPAN('1 year')` somewhere in the query.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [2015年二月20日 00:21 UTC](https://meta.discourse.org/t/badge-notifications-not-being-sent-for-newly-created-badges-that-are-retroactive/25426/6 "2015-02-20T00:21:06Z")

</div>

my concern is around the 1 post per year req check, for each user you need to break it down to an artificial set with year-start / year-end and then join to that. it can get to be an expensive query.

---

<div class="post-metadata">

### Author: ![DeanMarkTaylor](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/deanmarktaylor/32/102462_2.png) [@DeanMarkTaylor](https://meta.discourse.org/u/DeanMarkTaylor)
#### Post date: [2015年七月6日 18:34 UTC](https://meta.discourse.org/t/badge-notifications-not-being-sent-for-newly-created-badges-that-are-retroactive/25426/7 "2015-07-06T18:34:52Z")

</div>

Just checking out badges again…

I feel like I’ve missed some notifications here again…

If you compare the following graphic with the one in my first post - I don’t believe I have received notifications for the red arrowed ones:

 ![](https://global.discourse-cdn.com/meta/original/3X/2/3/236ac09b11de485f55e8c67eb44ae37567a4b214.png)

---

<div class="post-metadata">

### Author: ![riking](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/riking/32/170938_2.png) [@riking](https://meta.discourse.org/u/riking)
#### Post date: [2015年七月6日 20:40 UTC](https://meta.discourse.org/t/badge-notifications-not-being-sent-for-newly-created-badges-that-are-retroactive/25426/8 "2015-07-06T20:40:20Z")

</div>

That’s probably because they’re bronze badges, and they got backdated past the notification cutoff date… we should either nix that notification cutoff or fix the badges

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [2015年七月7日 02:36 UTC](https://meta.discourse.org/t/badge-notifications-not-being-sent-for-newly-created-badges-that-are-retroactive/25426/9 "2015-07-07T02:36:22Z")

</div>

> [@riking](#):
>
> nix that notification cutoff

Not sure about that, it will probably end up being notification central if we do that.

We need a proper strategy of dealing with badge floods before doing any of that.

---

<div class="post-metadata">

### Author: ![DeanMarkTaylor](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/deanmarktaylor/32/102462_2.png) [@DeanMarkTaylor](https://meta.discourse.org/u/DeanMarkTaylor)
#### Post date: [2016年三月16日 22:36 UTC](https://meta.discourse.org/t/badge-notifications-not-being-sent-for-newly-created-badges-that-are-retroactive/25426/10 "2016-03-16T22:36:08Z")

</div>

Again just to mention I don’t believe I received notifications for the following:

- 20 Nice Share badges
- 3 popular link badges

(I **might** have received notifications for 1 or 2 - but not 20+)

 ![](https://global.discourse-cdn.com/meta/original/3X/9/c/9c705626a12beafca4323473c0bc313020e81bef.png)

More recently I **have** been receiving notifications for new “Bug Reporter” badges.

---

<div class="post-metadata">

### Author: ![riking](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/riking/32/170938_2.png) [@riking](https://meta.discourse.org/u/riking)
#### Post date: [2016年三月16日 22:59 UTC](https://meta.discourse.org/t/badge-notifications-not-being-sent-for-newly-created-badges-that-are-retroactive/25426/11 "2016-03-16T22:59:41Z")

</div>

Again, the granted\_at field for those badges is broken… they are “awarded” “on” the date of the post, not the date of the Nth share.

---

<div class="post-metadata">

### Author: ![DeanMarkTaylor](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/deanmarktaylor/32/102462_2.png) [@DeanMarkTaylor](https://meta.discourse.org/u/DeanMarkTaylor)
#### Post date: [2016年三月16日 23:14 UTC](https://meta.discourse.org/t/badge-notifications-not-being-sent-for-newly-created-badges-that-are-retroactive/25426/12 "2016-03-16T23:14:43Z")

</div>

> [@riking](#):
>
> Again, the granted\_at field for those badges is broken… they are “awarded” “on” the date of the post, not the date of the Nth share.

“broken” - thanks for the clarification - this I understand.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [2016年三月16日 23:16 UTC](https://meta.discourse.org/t/badge-notifications-not-being-sent-for-newly-created-badges-that-are-retroactive/25426/13 "2016-03-16T23:16:43Z")

</div>

Technically Nth share is a nightmare wrapped in 3 other nightmares to calculate, but we could simple set granted at for these badges to “now”

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [2016年三月16日 23:34 UTC](https://meta.discourse.org/t/badge-notifications-not-being-sent-for-newly-created-badges-that-are-retroactive/25426/14 "2016-03-16T23:34:23Z")

</div>

Fixed per:

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

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [2016年三月16日 23:34 UTC](https://meta.discourse.org/t/badge-notifications-not-being-sent-for-newly-created-badges-that-are-retroactive/25426/15 "2016-03-16T23:34:32Z")

</div>


