Skip to content

fixes related to database/account-info/leaderboard.js - #565

Open
btfcookies wants to merge 1 commit into
qbreader:mainfrom
btfcookies:fix/leaderboard-aggregation
Open

fixes related to database/account-info/leaderboard.js#565
btfcookies wants to merge 1 commit into
qbreader:mainfrom
btfcookies:fix/leaderboard-aggregation

Conversation

@btfcookies

Copy link
Copy Markdown
Contributor

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

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant