Skip to content

Commit

Permalink
Merge pull request #49 from unmonk/v0.2
Browse files Browse the repository at this point in the history
chunking adjustments to updateScheduledMatchup and getActiveMatchupsB…
  • Loading branch information
unmonk authored Feb 17, 2025
2 parents f9e9507 + dc5d316 commit a926a7d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
6 changes: 3 additions & 3 deletions convex/matchups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,10 @@ export const getActiveMatchupsByLeague = query({
handler: async (ctx, { league }) => {
const matchups = await ctx.db
.query("matchups")
.filter((q) =>
q.and(q.eq(q.field("league"), league), q.eq(q.field("active"), true))
.withIndex("by_active_league", (q) =>
q.eq("league", league).eq("active", true)
)
.take(50);
.take(250);

// Get pick counts for each matchup
const matchupsWithPicks = [];
Expand Down
22 changes: 12 additions & 10 deletions convex/schedules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,19 +148,21 @@ export const updateScheduledMatchup = internalMutation({
status: v.string(),
},
handler: async (ctx, { gameId, league, startTime, status }) => {
// Use index to efficiently query matchups
const matchups = await ctx.db
.query("matchups")
.filter((q) =>
q.and(
q.eq(q.field("league"), league),
q.eq(q.field("active"), true),
q.eq(q.field("gameId"), gameId)
)
.withIndex("by_active_league", (q) =>
q.eq("league", league).eq("active", true)
)
.take(500);
for (const matchup of matchups) {
await ctx.db.patch(matchup._id, { startTime, status });
}
.filter((q) => q.eq(q.field("gameId"), gameId))
.take(50);

// Batch update all matching matchups
await Promise.all(
matchups.map((matchup) =>
ctx.db.patch(matchup._id, { startTime, status })
)
);
},
});

Expand Down

0 comments on commit a926a7d

Please sign in to comment.