myheats

Live heats, scoring and leaderboard for sport events
git clone https://git.in0rdr.ch/myheats.git
Log | Files | Refs | Pull requests |Archive | README | LICENSE

commit 69ad84192c929fb55b73810a7f41a9b06590772a
parent ed78f3a09cbbeb427f0fba0df9d3ba28717529ba
Author: Andreas Gruhler <agruhl@gmx.ch>
Date:   Mon,  9 Mar 2026 23:31:23 +0100

feat(137): reduce publicOnly queries

Diffstat:
Msrc/api/db.cjs | 51+++++++++++++++------------------------------------
1 file changed, 15 insertions(+), 36 deletions(-)

diff --git a/src/api/db.cjs b/src/api/db.cjs @@ -92,18 +92,10 @@ async function getUser(email) { async function allHeats(publicOnly) { try { - let heats = undefined - if (publicOnly) { - heats = await sql` - select * from heats - where private = false - ` - } else { - // return all heats (private & public) - heats = await sql` - select * from heats - ` - } + const heats = await sql` + select * from heats as h + where (${publicOnly} = false or h.private = false) + ` return heats } catch (error) { console.error('Error occurred in allHeats:', error); @@ -355,30 +347,17 @@ async function startlistWithAthletes(heatId) { async function scoresForHeatAndAthlete(heat, athlete, publicOnly) { try { - let score = undefined - if (publicOnly) { - score = await sql` - select - s.id, - s.athlete, - s.judge, - s.score - from public.scores as s - join public.heats as h - on s.heat = h.id - where s.heat = ${heat} and s.athlete = ${athlete} and h.private = false; - ` - } else { - // return all heats (private & public) - score = await sql` - select - id, - athlete, - judge, - score - from public.scores where heat = ${heat} and athlete = ${athlete}; - ` - } + const score = await sql` + select + s.id, + s.athlete, + s.judge, + s.score + from public.scores as s + join public.heats as h + on s.heat = h.id + where s.heat = ${heat} and s.athlete = ${athlete} and (${publicOnly} = false or h.private = false); + ` return score } catch (error) { console.error('Error occurred in scoresForHeatAndAthlete:', error);