Turns out the snippet in templates/comments.html was necessary to
get proper behavior in notifications.
Might come back to debug this later, but people use notifications more
than they deal with edge case self-upvotes, so reverting for now.
The changes to prevent coin fuckery with self-upvoting appear to work
correctly in the wild, so leaving those in place.
Implements feature request to know how many of each badge exists and
to have a 'rarity', a la Steam or PSN badges, relative to number of
non-lurker users.
Because Postgres `COUNT()`s are notoriously costly, /badges has been
memoized for 1hr to avoid a DOS target.
Fixes minor UI bug when removing self-upvote on a comment. Previous
behavior, starting from a new comment:
- Initial state: score 1 from self-upvote, upvote button shows
highlighted as `color: var(--primary)`.
- Click on upvote button to remove self-upvote → button
unhighlights, score displays as 0.
- [reload page]
- Score displays as 0, but button is highlighted.
- Click on upvote button → button unhighlights, score displays
as -1. [If you reload the page now, state is score 0 &
highlighted; no change in serverside votes.]
- Click on upvote again → button highlights, score displays as 0.
- [reload page]
- Score displays as 1, button is highlighted.
Direct cause is `templates/comments.html @ L115-117`. I checked
`api_comment`, though, and it adds a vote on new comments, and that
state change propagates to the template's parameters before it renders,
so I believe the only time this triggers is specifically when a user
has removed their self-upvote. Bug is fixed when testing with L115-117
removed. Is there some other edge case it was meant to solve?
Secondary bugfix: Removing a self-upvote _costs_ you a coin & a
truescore point. I think this is one of the few ways to get negative
dramacoin. I chose to fix it by having self-votes and self-unvotes not
change coins/truecoins. The alternative of having new comments & posts
give the user +1 coin/truecoin would modify site behavior, and you'd
retroactively owe some powerusers thousands of DC & truescore.