Skip to content
This repository was archived by the owner on May 11, 2026. It is now read-only.

Commit 00ba835

Browse files
committed
perf: improve leaderboard mysql query
1 parent f0c6345 commit 00ba835

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

src/graphql/operations/leaderboards.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,20 @@ export default async function (parent, args) {
2929
let orderDirection = (args.orderDirection || 'desc').toUpperCase();
3030
if (!['ASC', 'DESC'].includes(orderDirection)) orderDirection = 'DESC';
3131

32-
const orderQuery = uniq([orderBy, ...ORDER_FIELDS])
32+
// Use a single extra field for deterministic ordering
33+
// depending on the realm (space or user)
34+
// This covers 100% of our use cases
35+
// Missing realm is coming from queries not used by our UI
36+
const orderFields = [orderBy];
37+
if (where.space) {
38+
orderFields.push('user');
39+
} else if (where.user) {
40+
orderFields.push('space');
41+
} else {
42+
orderFields.push('last_vote');
43+
}
44+
45+
const orderQuery = uniq(orderFields)
3346
.map((field: string) => `l.${field} ${orderDirection}`)
3447
.join(', ');
3548

0 commit comments

Comments
 (0)