Skip to content

Commit

Permalink
prevent contest state from being updated if it's the same
Browse files Browse the repository at this point in the history
  • Loading branch information
merklejerk committed Jun 16, 2024
1 parent 4c9854b commit 70001fe
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
33 changes: 29 additions & 4 deletions src/routes/(app)/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
onMount(() => {
if (LAUNCHED) {
loadContestState();
refreshTimer = setInterval(loadContestState, 60e3);
refreshTimer = setInterval(loadContestState, 10e3);
}
});
Expand Down Expand Up @@ -100,9 +100,34 @@
}
async function loadContestState(): Promise<void> {
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() {
Expand Down
7 changes: 0 additions & 7 deletions src/routes/(app)/players/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,6 @@
> * {
padding: 0 !important;
}
> .counter {
}
> .submitted {
color: green;
}
> .name {
text-align: left;
Expand Down

0 comments on commit 70001fe

Please sign in to comment.