Stackoverflow has a nifty badge system. One thing I noticed is that badges are not immediately awarded, but sometimes seem to have some type of a delay after I meet the criteria. I've noticed this on some other sites that have badges as well.
Presumably this is because they are using a delayed job that scans periodically to see if any new badges need to be awarded. I see this approach also advised here:
How to implement badges?
However, I don't really see why this should be necessary, and am favoring in my implementation to simply have a system where after a relevant action is performed, for example a new comment is posted, a checkAwardBadge function is called, which checks if the user meets the criteria for a new comment badge.
Speedwise, I was thinking that all relevant user stats would simply be stashed in a submodel of User, like UserStats so that instead of having to count the number of comments each time, it would just be a simple query.
It strikes me that the system I'm favoring should be fast and very simple to understand. Are there downsides I'm missing here on why it's necessary to complicate things with delayed jobs?
To clarify: I plan to have an abstract class Achievements, with each actual Achievement an implementation of Achievements. Each Achievement will have a checkAwardBadge function, which can be called from the controller, or even a delayed job if I should choose to go that route, or any time really, to check whether a user has earned a certain badge. Thus, achievement code would all be centralized.
Badges are little bits of digital flair that you earn for almost every kind of activity. The number and type of badges you've earned are displayed together with your name and reputation score around your team as part of your user card. The badge system exists for two reasons...
To this day we have awarded over 66 million badges to more than 8.6 million users. The most common badge is the “popular question,” which has been given out over five million times, and is awarded to users who ask a question that is viewed 1000 times.
Silver badges are more uncommon than bronze badges, but attainable if you're dedicated. Gold badges. Gold badges are for the most committed users. They reward the most difficult feats; you'll have to not only participate in the community but be skilled, knowledgeable, and dedicated to earn these.
Your implementation may work on simple scenarios (like the one you are describing), but if things gets more complex you have a solution that:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With