-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
base: main
Are you sure you want to change the base?
Conversation
…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) |
There was a problem hiding this comment.
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?
This pull request has been mentioned on Discourse Meta. There might be relevant details there: |
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. |
.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)) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 🧐
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 aNOT IN
) added here: b704e33