fixes related to database/account-info/leaderboard.js - #565
Open
btfcookies wants to merge 1 commit into
Open
Conversation
These are independent of any new endpoint. All three affect /api/admin/leaderboard and client/admin/leaderboard as they stand today. routes/api/admin/leaderboard.js passes limit = null when ?limit is absent, and slice(0, null) coerces the end index to 0, so the admin leaderboard currently returns an empty array. A falsy limit now returns every row; a real limit behaves as before. A user deleted since their buzzes were recorded misses the $lookup, so $arrayElemAt yields no username. mergeTwoSortedArrays compares usernames with < and >, and both comparisons are false against a missing username, so every deleted user is treated as the same person. Where the two inputs hold unequal numbers of such rows the merge desynchronises: a deleted user absorbs a live user's bonus counts, and that user's own row is left understating them. These rows are now dropped before the merge. The inputs were ordered by a $sort stage, which compares strings by their UTF-8 bytes, while the merge compares UTF-16 code units. The two disagree for characters outside the Basic Multilingual Plane, which UTF-8 orders after every BMP character but UTF-16 orders among the surrogates, ahead of U+E000 through U+FFFF. When such a user appears in one input but not the other, the merge emits them as two rows instead of one. Both inputs are now sorted in JS with the same comparison the merge uses, which also removes an unindexed server-side sort. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.
same as the ones in #561: slice(0, limit) returned [] when limit was omitted, deleted users left rows that didn't have usernames, mergeTwoSortedArrays didn't match MongoDB's sort outside of ASCII, which split not ASCII usernames into 2 rows.
all fixes tested locally