[go: up one dir, main page]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Ensure subsequent Anniversary badges are granted on a user's anniversary date #28979

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

magni-
Copy link
@magni- magni- commented Sep 20, 2024

With the current implementation, badges are granted on the end date. Since the job only runs once a day,
this can cause drift, with the badge granted a day later than the previous year.

Context: https://meta.discourse.org/t/some-anniversary-badges-are-awarded-one-day-and-one-year-after-the-last-anniversary-badge/325533

I have FUD regarding performance due to the changes here partially reverting the performance enhancement (i.e. switching back to a LEFT JOIN from a NOT IN) added here: b704e33

…iversary date

With the current implementation, badges are granted on the end date. Since the job only runs once a day,
this can cause drift, with the badge granted a day later than the previous year.

Context: https://meta.discourse.org/t/some-anniversary-badges-are-awarded-one-day-and-one-year-after-the-last-anniversary-badge/325533
expect(badge.count).to eq(2)
expect(badge.second.granted_at).to eq_time(badge.first.granted_at + 2.years)
expect(badge.second.granted_at.year).to eq(Date.today.year)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line isn't strictly needed two years from 700 days ago can only be the current year, but I figured it wouldn't hurt to make this check explicit?

@discoursebot
Copy link

This pull request has been mentioned on Discourse Meta. There might be relevant details there:

https://meta.discourse.org/t/some-anniversary-badges-are-awarded-one-day-and-one-year-after-the-last-anniversary-badge/325533/4

Copy link

This pull request has been automatically marked as stale because it has been open for 60 days with no activity. To keep it open, remove the stale tag, push code, or add a comment. Otherwise, it will be closed in 14 days.

@github-actions github-actions bot added the Stale label Nov 20, 2024
@pmusaraj pmusaraj removed the Stale label Nov 20, 2024
.find_each do |user|
anniversary_date = user_ids_to_anniversary_dates[user.id] || start_date
years_ago = Date.today.year - anniversary_date.year
BadgeGranter.grant(badge, user, created_at: anniversary_date.advance(years: years_ago))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we're still using granted_at as our "base" it will still be delayed (though won't "slide" year after year anymore). A proper fix would be to always use the users.created_at and advance it (or maybe using change(year: XXX) might be easier / better?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For bonus points, might be worth considering how to fix existing badges 🧐

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants