From d117090fcae3ccd43600c60181b5e30d2dc3f7a4 Mon Sep 17 00:00:00 2001 From: Matt Date: Thu, 19 Feb 2026 09:35:58 +0100 Subject: [PATCH] Fix rounds page showing inflated project count 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 --- src/app/(admin)/admin/rounds/page.tsx | 2 +- src/server/routers/competition.ts | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/app/(admin)/admin/rounds/page.tsx b/src/app/(admin)/admin/rounds/page.tsx index 3633796..2da7ccf 100644 --- a/src/app/(admin)/admin/rounds/page.tsx +++ b/src/app/(admin)/admin/rounds/page.tsx @@ -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') diff --git a/src/server/routers/competition.ts b/src/server/routers/competition.ts index 4bcb077..6ee3472 100644 --- a/src/server/routers/competition.ts +++ b/src/server/routers/competition.ts @@ -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 } }), /**