perf(convex): bound unbounded owner-wide collects on hot paths

This commit is contained in:
Gabriel Brown
2026-07-11 14:41:31 -04:00
parent e4a7f96633
commit 9067d16734
3 changed files with 300 additions and 10 deletions
+20 -8
View File
@@ -23,14 +23,26 @@ export const listForSpoon = query({
.order('desc')
.take(limit ?? 100);
}
const commits = await ctx.db
.query('spoonCommits')
.withIndex('by_owner', (q) => q.eq('ownerId', ownerId))
.order('desc')
.collect();
return commits
.filter((commit) => commit.spoonId === spoonId)
.slice(0, limit ?? 100);
const take = limit ?? 100;
const [upstream, fork] = await Promise.all([
ctx.db
.query('spoonCommits')
.withIndex('by_spoon_side', (q) =>
q.eq('spoonId', spoonId).eq('side', 'upstream'),
)
.order('desc')
.take(take),
ctx.db
.query('spoonCommits')
.withIndex('by_spoon_side', (q) =>
q.eq('spoonId', spoonId).eq('side', 'fork'),
)
.order('desc')
.take(take),
]);
return [...upstream, ...fork]
.sort((a, b) => (b.committedAt ?? 0) - (a.committedAt ?? 0))
.slice(0, take);
},
});