From 68e35b8f55ef57d9f9f529bbb619be1d3f6b8f4e Mon Sep 17 00:00:00 2001 From: Noam Gaash Date: Tue, 21 May 2024 20:31:33 +0300 Subject: [PATCH] perf(SingleLinePage): don't fetch irrelevant data (#761) --- src/api/useVehicleLocations.ts | 3 +++ src/hooks/useSingleLineData.ts | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/api/useVehicleLocations.ts b/src/api/useVehicleLocations.ts index 23323aa1..ae0c9711 100644 --- a/src/api/useVehicleLocations.ts +++ b/src/api/useVehicleLocations.ts @@ -166,16 +166,19 @@ export default function useVehicleLocations({ lineRef, operatorRef, splitMinutes: split = 1, + pause = false, }: { from: Dateable to: Dateable lineRef?: number operatorRef?: number splitMinutes?: false | number + pause?: boolean }) { const [locations, setLocations] = useState([]) const [isLoading, setIsLoading] = useState([]) useEffect(() => { + if (pause) return const range = split ? getMinutesInRange(from, to, split) : [{ from, to }] setIsLoading(range.map(() => true)) const unmounts = range.map(({ from, to }, i) => diff --git a/src/hooks/useSingleLineData.ts b/src/hooks/useSingleLineData.ts index c9991462..a9652d2f 100644 --- a/src/hooks/useSingleLineData.ts +++ b/src/hooks/useSingleLineData.ts @@ -18,7 +18,8 @@ export const useSingleLineData = (lineRef?: number, routeIds?: number[]) => { from: +new Date(timestamp).setHours(0, 0, 0, 0), to: +new Date(timestamp).setHours(23, 59, 59, 999), lineRef, - splitMinutes: 20, + splitMinutes: 60, + pause: !lineRef, }) const positions = useMemo(() => {