Fix rounds page showing inflated project count
All checks were successful
Build and Push Docker Image / build (push) Successful in 9m29s

The "537 projects" count was summing projectRoundStates across all
rounds, so a project in 3 rounds was counted 3 times. Now queries
distinct projectIds across all competition rounds to show the actual
unique project count (214).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Matt
2026-02-19 09:35:58 +01:00
parent 099157bf74
commit d117090fca
2 changed files with 12 additions and 2 deletions

View File

@@ -283,7 +283,7 @@ export default function RoundsPage() {
// ─── Main Render ───────────────────────────────────────────────────────── // ─── Main Render ─────────────────────────────────────────────────────────
const activeFilter = filterType !== 'all' const activeFilter = filterType !== 'all'
const totalProjects = rounds.reduce((s, r) => s + r._count.projectRoundStates, 0) const totalProjects = (compDetail as any)?.distinctProjectCount ?? 0
const totalAssignments = rounds.reduce((s, r) => s + r._count.assignments, 0) const totalAssignments = rounds.reduce((s, r) => s + r._count.assignments, 0)
const activeRound = rounds.find((r) => r.status === 'ROUND_ACTIVE') const activeRound = rounds.find((r) => r.status === 'ROUND_ACTIVE')

View File

@@ -122,7 +122,17 @@ export const competitionRouter = router({
throw new TRPCError({ code: 'NOT_FOUND', message: 'Competition not found' }) throw new TRPCError({ code: 'NOT_FOUND', message: 'Competition not found' })
} }
return competition // Count distinct projects across all rounds (not sum of per-round states)
const roundIds = competition.rounds.map((r) => r.id)
const distinctProjectCount = roundIds.length > 0
? await ctx.prisma.projectRoundState.findMany({
where: { roundId: { in: roundIds } },
select: { projectId: true },
distinct: ['projectId'],
}).then((rows) => rows.length)
: 0
return { ...competition, distinctProjectCount }
}), }),
/** /**