-
Notifications
You must be signed in to change notification settings - Fork 482
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
Optimize generate_username query #12745
Conversation
You'll need to fix the failing tests... |
oh, (looking at the failing tests) I didn't realize that the username field has a max length of only 20 characters! This constraint makes me much more hesitant to increase the average number of digits in the first part of this algorithm... |
Is this still active? |
tweak darts logic for longer suffixes
The performance issue this PR hopes to address is still at large and getting increasingly problematic over time, so I took another pass at this PR today to address the test failures. |
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.
Looks good. I'm assuming that there should be no change to the index(es) used? Did you do an explain on the new query? Also, do you have any timing metrics?
LGTM |
Here's a basic
Manual timing tests confirm the new query is consistently faster than the original (and in some edge cases where the original hangs for minutes, the new query finishes in ~5 seconds). |
Revert "Optimize generate_username query (#12745)"
This PR optimizes the
UserHelpers#generate_username
logic in three ways:Not 100% confident that 2 and 3 are the best approach, but I'm reasonably confident they're improvements over the existing logic. However, it's possible we might want to adopt
friendly_id
instead, and rely on that library's well-maintained conflict-resolution implementation rather than continuing to maintain this logic ourselves.