recalc user statistics using sql#19
Open
arily wants to merge 4 commits into
Open
Conversation
marcandreher
requested changes
Aug 4, 2025
marcandreher
left a comment
Member
There was a problem hiding this comment.
Indeed good stuff, but I prefer to not change the db structure atm, or there is a auto migration that adds that?
Author
No db structures has been changed. Just add few indexes speed up queries. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Describe your changes
recalc user statistics using sql
we are running this code for few months, and eliminated few bugs during testing.
atomic updates on beatmap statistics
I don't feel boatmap play count needs to be accurate but if needed we can also count from submitted scores.
benefits
will dramatically speed up score submission.
for our server (ppy.sb), in extreme cases (multiplay, multiple user, heavy user), user will experience score submission speed up from few minutes to seconds.
I believe this change could also in theory make removing the implemented global submission lock possible, therefore further increase parallel performance for multiple user submitting scores.
Such lock is for prevent increasing user stat twice for same score, bpy will / should check checksum to not allow multiple same score inserted into db.
handles db changes naturally.
other than using our recalc utils (mentioned below), all stats will be updated after user submit any score, if proceed any database modifications eg. delete score, rank custom maps, recalc score stats.
I believe some sort of indexes are required for the calculation to run smoothly.
we have 2 compound indexes:
map-leaderboard (map_md5, mode, status)user-best (userid, mode, status, pp)these are for both recalc and our frontend.
Related Issues / Projects
we also have offline recalc utility if anything messed up:
https://github.com/ppy-sb/nyamatrix
Checklist