From 2d963c16f31438b72d2ac8711482014bffe547c6 Mon Sep 17 00:00:00 2001 From: "2569718930@qq.com" <2569718930@qq.com> Date: Sun, 31 May 2026 21:17:38 +0800 Subject: [PATCH] Coalesce terminal chart detail loads --- .../scan-terminal/LiveTemperatureThresholdChart.tsx | 9 +++------ .../scan-terminal/__tests__/refreshCadencePolicy.test.ts | 5 +++++ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/frontend/components/dashboard/scan-terminal/LiveTemperatureThresholdChart.tsx b/frontend/components/dashboard/scan-terminal/LiveTemperatureThresholdChart.tsx index 2644ffbd..6faed4bb 100644 --- a/frontend/components/dashboard/scan-terminal/LiveTemperatureThresholdChart.tsx +++ b/frontend/components/dashboard/scan-terminal/LiveTemperatureThresholdChart.tsx @@ -56,6 +56,7 @@ const PEAK_GLOW_BADGE_CLASS = { } as const; const PROBABILITY_REFRESH_AFTER_PATCH_MS = 60_000; +const DETAIL_LOAD_BATCH_DELAY_MS = 0; const TemperatureChartCanvas = dynamic( () => @@ -134,7 +135,6 @@ export function LiveTemperatureThresholdChart({ isMaximized = false, disableClose = false, isActive = !compact, - slotIndex = 0, }: { isEn: boolean; row: ScanOpportunityRow | null; @@ -274,9 +274,6 @@ export function LiveTemperatureThresholdChart({ setIsHourlyLoading(true); let cancelled = false; - // Prioritize active slots, stagger/delay background slots to optimize load performance - const delay = isActive ? 0 : (slotIndex ? 300 + slotIndex * 250 : 350); - const timer = setTimeout(() => { fetchHourlyForecastForCity(city, { resolution: targetResolution }) .then((data) => { @@ -296,13 +293,13 @@ export function LiveTemperatureThresholdChart({ .finally(() => { if (!cancelled) setIsHourlyLoading(false); }); - }, delay); + }, DETAIL_LOAD_BATCH_DELAY_MS); return () => { cancelled = true; clearTimeout(timer); }; - }, [city, row, isActive, slotIndex, targetResolution, isChartVisible, detailRetryNonce, isEn]); + }, [city, row, targetResolution, isChartVisible, detailRetryNonce, isEn]); useEffect(() => { if (!latestPatch || latestPatch.revision <= lastAppliedPatchRevisionRef.current) return; diff --git a/frontend/components/dashboard/scan-terminal/__tests__/refreshCadencePolicy.test.ts b/frontend/components/dashboard/scan-terminal/__tests__/refreshCadencePolicy.test.ts index dbb15f83..231f612d 100644 --- a/frontend/components/dashboard/scan-terminal/__tests__/refreshCadencePolicy.test.ts +++ b/frontend/components/dashboard/scan-terminal/__tests__/refreshCadencePolicy.test.ts @@ -131,6 +131,11 @@ export async function runTests() { chartSource.includes("isChartVisible"), "city detail prefetch should be gated to visible chart cards instead of every mounted slot", ); + assert( + chartSource.includes("DETAIL_LOAD_BATCH_DELAY_MS") && + !chartSource.includes("slotIndex ? 300 + slotIndex * 250"), + "visible chart detail loads should enter the batch queue together instead of being staggered into single-city requests", + ); assert( chartSource.includes("allowStale: true") && chartCanvasSourceIncludes(chartSource, "数据暂不可用") &&