Coalesce terminal chart detail loads
This commit is contained in:
@@ -56,6 +56,7 @@ const PEAK_GLOW_BADGE_CLASS = {
|
|||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
const PROBABILITY_REFRESH_AFTER_PATCH_MS = 60_000;
|
const PROBABILITY_REFRESH_AFTER_PATCH_MS = 60_000;
|
||||||
|
const DETAIL_LOAD_BATCH_DELAY_MS = 0;
|
||||||
|
|
||||||
const TemperatureChartCanvas = dynamic(
|
const TemperatureChartCanvas = dynamic(
|
||||||
() =>
|
() =>
|
||||||
@@ -134,7 +135,6 @@ export function LiveTemperatureThresholdChart({
|
|||||||
isMaximized = false,
|
isMaximized = false,
|
||||||
disableClose = false,
|
disableClose = false,
|
||||||
isActive = !compact,
|
isActive = !compact,
|
||||||
slotIndex = 0,
|
|
||||||
}: {
|
}: {
|
||||||
isEn: boolean;
|
isEn: boolean;
|
||||||
row: ScanOpportunityRow | null;
|
row: ScanOpportunityRow | null;
|
||||||
@@ -274,9 +274,6 @@ export function LiveTemperatureThresholdChart({
|
|||||||
setIsHourlyLoading(true);
|
setIsHourlyLoading(true);
|
||||||
let cancelled = false;
|
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(() => {
|
const timer = setTimeout(() => {
|
||||||
fetchHourlyForecastForCity(city, { resolution: targetResolution })
|
fetchHourlyForecastForCity(city, { resolution: targetResolution })
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
@@ -296,13 +293,13 @@ export function LiveTemperatureThresholdChart({
|
|||||||
.finally(() => {
|
.finally(() => {
|
||||||
if (!cancelled) setIsHourlyLoading(false);
|
if (!cancelled) setIsHourlyLoading(false);
|
||||||
});
|
});
|
||||||
}, delay);
|
}, DETAIL_LOAD_BATCH_DELAY_MS);
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
cancelled = true;
|
cancelled = true;
|
||||||
clearTimeout(timer);
|
clearTimeout(timer);
|
||||||
};
|
};
|
||||||
}, [city, row, isActive, slotIndex, targetResolution, isChartVisible, detailRetryNonce, isEn]);
|
}, [city, row, targetResolution, isChartVisible, detailRetryNonce, isEn]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!latestPatch || latestPatch.revision <= lastAppliedPatchRevisionRef.current) return;
|
if (!latestPatch || latestPatch.revision <= lastAppliedPatchRevisionRef.current) return;
|
||||||
|
|||||||
@@ -131,6 +131,11 @@ export async function runTests() {
|
|||||||
chartSource.includes("isChartVisible"),
|
chartSource.includes("isChartVisible"),
|
||||||
"city detail prefetch should be gated to visible chart cards instead of every mounted slot",
|
"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(
|
assert(
|
||||||
chartSource.includes("allowStale: true") &&
|
chartSource.includes("allowStale: true") &&
|
||||||
chartCanvasSourceIncludes(chartSource, "数据暂不可用") &&
|
chartCanvasSourceIncludes(chartSource, "数据暂不可用") &&
|
||||||
|
|||||||
Reference in New Issue
Block a user