diff --git a/backend/src/db/functions/noteworthy_matches.py b/backend/src/db/functions/noteworthy_matches.py index 889b238a..017f22fe 100644 --- a/backend/src/db/functions/noteworthy_matches.py +++ b/backend/src/db/functions/noteworthy_matches.py @@ -55,14 +55,14 @@ def callback(session: SessionType): matches.add_columns( func.greatest(red_score_col, blue_score_col).label("max_score") ) - .order_by(desc("max_score"), asc(MatchORM.time)) # type: ignore + .order_by(desc("max_score").nullslast(), asc(MatchORM.time)) # type: ignore .limit(30) .all() ) combined_score_matches = ( matches.add_columns((red_score_col + blue_score_col).label("sum_score")) # type: ignore - .order_by(desc("sum_score"), asc(MatchORM.time)) # type: ignore + .order_by(desc("sum_score").nullslast(), asc(MatchORM.time)) # type: ignore .limit(30) .all() ) @@ -73,7 +73,7 @@ def callback(session: SessionType): "losing_score" ), ) - .order_by(desc("losing_score"), asc(MatchORM.time)) # type: ignore + .order_by(desc("losing_score").nullslast(), asc(MatchORM.time)) # type: ignore .limit(30) .all() ) @@ -86,7 +86,7 @@ def callback(session: SessionType): "max_auto_score" ) ) - .order_by(desc("max_auto_score"), asc("time")) # type: ignore + .order_by(desc("max_auto_score").nullslast(), asc("time")) # type: ignore .limit(30) .all() ) @@ -97,7 +97,7 @@ def callback(session: SessionType): "max_teleop_score" ) ) - .order_by(desc("max_teleop_score"), asc("time")) # type: ignore + .order_by(desc("max_teleop_score").nullslast(), asc("time")) # type: ignore .limit(30) .all() ) @@ -108,7 +108,7 @@ def callback(session: SessionType): "max_endgame_score" ) ) - .order_by(desc("max_endgame_score"), asc("time")) # type: ignore + .order_by(desc("max_endgame_score").nullslast(), asc("time")) # type: ignore .limit(30) .all() ) diff --git a/frontend/src/api/storage.tsx b/frontend/src/api/storage.tsx index d5b17b19..f7db1ebe 100644 --- a/frontend/src/api/storage.tsx +++ b/frontend/src/api/storage.tsx @@ -37,19 +37,14 @@ export function decompress(buffer: any) { return data; } -async function query( +const inFlight: { [storageKey: string]: Promise } = {}; + +async function fetchAndStore( storageKey: string, apiPath: string, checkBucket: boolean, - minLength: number, expiry: number ) { - const cacheData = await getWithExpiry(storageKey); - if (cacheData && (minLength === 0 || cacheData?.length > minLength)) { - log(`Used Local Storage: ${storageKey}`); - return cacheData; - } - const start = performance.now(); let buffer = null; @@ -85,4 +80,26 @@ async function query( } } +async function query( + storageKey: string, + apiPath: string, + checkBucket: boolean, + minLength: number, + expiry: number +) { + const cacheData = await getWithExpiry(storageKey); + if (cacheData && (minLength === 0 || cacheData?.length > minLength)) { + log(`Used Local Storage: ${storageKey}`); + return cacheData; + } + + if (!inFlight[storageKey]) { + inFlight[storageKey] = fetchAndStore(storageKey, apiPath, checkBucket, expiry).finally(() => { + delete inFlight[storageKey]; + }); + } + + return inFlight[storageKey]; +} + export default query; diff --git a/frontend/src/pagesContent/shared/notFound.tsx b/frontend/src/pagesContent/shared/notFound.tsx index 0f03fa67..269bd50f 100644 --- a/frontend/src/pagesContent/shared/notFound.tsx +++ b/frontend/src/pagesContent/shared/notFound.tsx @@ -11,7 +11,7 @@ const NotFound = ({ type }: { type: string }) => { useEffect(() => { setTimeout(() => { setRender(true); - }, 8000); + }, 1500); }, []); if (!render) {