perf(tracks): coalesce address lookups

This commit is contained in:
lingniu
2026-07-16 06:22:37 +08:00
parent 41e2b1ab97
commit e6d26faad9
4 changed files with 52 additions and 9 deletions

View File

@@ -1,5 +1,22 @@
import type { HistoryLocationRow, TrackPlaybackEvent, TrackPlaybackResponse } from '../../api/types';
export const TRACK_ADDRESS_SETTLE_MS = 650;
export type TrackAddressCoordinate = { longitude: number; latitude: number; key: string };
export function trackAddressCoordinate(longitude?: number, latitude?: number): TrackAddressCoordinate | undefined {
if (!Number.isFinite(longitude) || !Number.isFinite(latitude)
|| Math.abs(longitude ?? 0) > 180 || Math.abs(latitude ?? 0) > 90
|| (longitude === 0 && latitude === 0)) return undefined;
const roundedLongitude = Number(longitude!.toFixed(4));
const roundedLatitude = Number(latitude!.toFixed(4));
return {
longitude: roundedLongitude,
latitude: roundedLatitude,
key: `${roundedLongitude.toFixed(4)},${roundedLatitude.toFixed(4)}`
};
}
export function formatDuration(seconds: number) {
const safe = Math.max(0, Math.floor(seconds || 0));
const hours = Math.floor(safe / 3600);