Return partial city detail batches
This commit is contained in:
@@ -96,6 +96,18 @@ export async function runTests() {
|
||||
chartLogicSource.includes("primeCityDetailCache"),
|
||||
"visible terminal chart detail fetches should be coalesced into one batch request and prime the shared chart cache",
|
||||
);
|
||||
assert(
|
||||
chartLogicSource.includes("partial?: boolean") &&
|
||||
chartLogicSource.includes("missing?: string[]"),
|
||||
"frontend city detail batch payload should understand partial responses and missing city markers",
|
||||
);
|
||||
const flushCityDetailBatchBlock = chartLogicSource.match(/async function flushCityDetailBatch[\s\S]*?\r?\n}\r?\n\r?\nfunction fetchCityDetailBatchWithTimeout/)?.[0] || "";
|
||||
assert(
|
||||
flushCityDetailBatchBlock.includes("partialMissingCities") &&
|
||||
flushCityDetailBatchBlock.includes("resolveBatchWaiters(waiters, null)") &&
|
||||
flushCityDetailBatchBlock.includes("payload?.partial === true"),
|
||||
"partial detail-batch misses should resolve without immediately issuing single-city fallback requests",
|
||||
);
|
||||
const fetchHourlyBlock = chartLogicSource.match(/async function fetchHourlyForecastForCity[\s\S]*?\r?\n}\r?\n\r?\nfunction fetchCityDetailWithTimeout/)?.[0] || "";
|
||||
assert(
|
||||
fetchHourlyBlock.includes("queueCityDetailBatch(city, resParam)") &&
|
||||
|
||||
@@ -966,8 +966,11 @@ type HourlyForecastFetchOptions = {
|
||||
};
|
||||
|
||||
type CityDetailBatchPayload = {
|
||||
cities?: string[];
|
||||
details?: Record<string, CityDetail | null | undefined>;
|
||||
errors?: Record<string, string>;
|
||||
missing?: string[];
|
||||
partial?: boolean;
|
||||
};
|
||||
|
||||
type CityDetailBatchWaiter = {
|
||||
@@ -1112,6 +1115,10 @@ async function flushCityDetailBatch(resolution: string) {
|
||||
try {
|
||||
const payload = await fetchCityDetailBatchWithTimeout(cities, resolution);
|
||||
const details = payload?.details || {};
|
||||
const partialMissingCities =
|
||||
payload?.partial === true
|
||||
? new Set((payload.missing || []).map((city) => normalizeCityKey(city)))
|
||||
: new Set<string>();
|
||||
await Promise.all(
|
||||
cities.map(async (city) => {
|
||||
const waiters = queue.waiters.get(city);
|
||||
@@ -1121,6 +1128,10 @@ async function flushCityDetailBatch(resolution: string) {
|
||||
resolveBatchWaiters(waiters, data);
|
||||
return;
|
||||
}
|
||||
if (partialMissingCities.has(normalizeCityKey(city))) {
|
||||
resolveBatchWaiters(waiters, null);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
resolveBatchWaiters(
|
||||
waiters,
|
||||
|
||||
Reference in New Issue
Block a user