Reduce terminal auth and analytics stalls
This commit is contained in:
@@ -96,7 +96,7 @@ 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",
|
||||
);
|
||||
const fetchHourlyBlock = chartLogicSource.match(/async function fetchHourlyForecastForCity[\s\S]*?\n}\n\nfunction fetchCityDetailWithTimeout/)?.[0] || "";
|
||||
const fetchHourlyBlock = chartLogicSource.match(/async function fetchHourlyForecastForCity[\s\S]*?\r?\n}\r?\n\r?\nfunction fetchCityDetailWithTimeout/)?.[0] || "";
|
||||
assert(
|
||||
fetchHourlyBlock.includes("queueCityDetailBatch(city, resParam)") &&
|
||||
!fetchHourlyBlock.includes("runQueuedHourlyDetailRequest"),
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import {
|
||||
createAuthProfileRequestCache,
|
||||
loadTerminalAuthProfile,
|
||||
type TerminalAuthProfilePayload,
|
||||
} from "@/components/dashboard/scan-terminal/terminal-auth-bootstrap";
|
||||
@@ -27,6 +28,41 @@ async function flushMicrotasks() {
|
||||
}
|
||||
|
||||
export async function runTests() {
|
||||
const pendingProfile = deferred<TerminalAuthProfilePayload>();
|
||||
let underlyingProfileLoads = 0;
|
||||
const cachedLoadAuthProfile = createAuthProfileRequestCache((
|
||||
accessToken?: string | null,
|
||||
options?: { preferSnapshot?: boolean },
|
||||
) => {
|
||||
underlyingProfileLoads += 1;
|
||||
assert(
|
||||
accessToken === "shared-token" && options?.preferSnapshot === true,
|
||||
"auth profile request cache should pass through the original token and snapshot preference",
|
||||
);
|
||||
return pendingProfile.promise;
|
||||
});
|
||||
const firstCachedProfile = cachedLoadAuthProfile("shared-token", {
|
||||
preferSnapshot: true,
|
||||
});
|
||||
const secondCachedProfile = cachedLoadAuthProfile("shared-token", {
|
||||
preferSnapshot: true,
|
||||
});
|
||||
assert(
|
||||
firstCachedProfile === secondCachedProfile && underlyingProfileLoads === 1,
|
||||
"auth profile request cache should dedupe identical in-flight profile loads",
|
||||
);
|
||||
pendingProfile.resolve({
|
||||
authenticated: true,
|
||||
user_id: "shared-user",
|
||||
subscription_active: true,
|
||||
});
|
||||
await firstCachedProfile;
|
||||
await cachedLoadAuthProfile("shared-token", { preferSnapshot: true });
|
||||
assert(
|
||||
underlyingProfileLoads === 2,
|
||||
"auth profile request cache should clear a key after the in-flight load settles",
|
||||
);
|
||||
|
||||
const slowCookieProfile = deferred<TerminalAuthProfilePayload>();
|
||||
const fastSession = deferred<{ data: { session: { access_token: string } } }>();
|
||||
const calls: string[] = [];
|
||||
|
||||
Reference in New Issue
Block a user