Fix rounds page showing inflated project count
All checks were successful
Build and Push Docker Image / build (push) Successful in 9m29s
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:
@@ -283,7 +283,7 @@ export default function RoundsPage() {
|
||||
// ─── Main Render ─────────────────────────────────────────────────────────
|
||||
|
||||
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 activeRound = rounds.find((r) => r.status === 'ROUND_ACTIVE')
|
||||
|
||||
|
||||
@@ -122,7 +122,17 @@ export const competitionRouter = router({
|
||||
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 }
|
||||
}),
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user