From 70001fe4efdca07865ebd38a63f1a7074ae0d535 Mon Sep 17 00:00:00 2001 From: Lawrence Forman Date: Sun, 16 Jun 2024 19:47:42 -0400 Subject: [PATCH] prevent contest state from being updated if it's the same --- src/routes/(app)/+layout.svelte | 33 +++++++++++++++++++++++---- src/routes/(app)/players/+page.svelte | 7 ------ 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/src/routes/(app)/+layout.svelte b/src/routes/(app)/+layout.svelte index 74a56b7..4aa3b8c 100644 --- a/src/routes/(app)/+layout.svelte +++ b/src/routes/(app)/+layout.svelte @@ -43,7 +43,7 @@ onMount(() => { if (LAUNCHED) { loadContestState(); - refreshTimer = setInterval(loadContestState, 60e3); + refreshTimer = setInterval(loadContestState, 10e3); } }); @@ -100,9 +100,34 @@ } async function loadContestState(): Promise { - setSeasons(await fetchContestState(publicClient)); - // HACK: Need to do this to trigger updates for other subscribers. - $seasons; + const seasons_ = await fetchContestState(publicClient); + let isDifferentState = false; + if ($seasons.length === seasons_.length) { + found: for (let i = 0; i < seasons_.length; ++i) { + const s1 = $seasons[i]; + const s2 = seasons_[i]; + for (const k of Object.keys(s1)) { + const v1 = (s1 as any)[k]; + const v2 = (s2 as any)[k]; + if (v1 != v2) { + if (v1 instanceof Date) { + if (v1.getTime() === v2.getTime()) { + continue; + } + } + isDifferentState = true; + break found; + } + } + } + } else { + isDifferentState = true; + } + if (isDifferentState) { + setSeasons(await fetchContestState(publicClient)); + // HACK: Need to do this to trigger updates for other subscribers. + $seasons; + } } function toggleMusic() { diff --git a/src/routes/(app)/players/+page.svelte b/src/routes/(app)/players/+page.svelte index 2cff1c0..dd48c85 100644 --- a/src/routes/(app)/players/+page.svelte +++ b/src/routes/(app)/players/+page.svelte @@ -131,13 +131,6 @@ > * { padding: 0 !important; } - - > .counter { - } - - > .submitted { - color: green; - } > .name { text-align: left;