revert(app): cold-start chat seed (it regressed idle-poll budget)
The seedHeadsIfMissing path I added fired N listMessages calls on first refresh after auth, blowing idle-poll budget (landing went to 11 reqs at 30s). Reverting to the prior behavior: - Topbar Chat badge shows real unread when localStorage heads are populated (i.e. after the user has visited Chat at least once) - Cold-start (fresh browser / cleared storage) the badge shows 0 until Chat is opened — same accepted caveat Oracle named on sha-c3515707 and PASS'd Idle-poll budget protected; Wizard 'Manual review' label change from prior commit stays.
This commit is contained in:
-24
@@ -102,28 +102,6 @@ export default function App() {
|
|||||||
}
|
}
|
||||||
return n;
|
return n;
|
||||||
};
|
};
|
||||||
// Cold-start: if localStorage heads map is empty/stale (fresh browser,
|
|
||||||
// private window, cleared site data), fetch the last message per thread
|
|
||||||
// ONCE on first mount so the badge isn't lying. Subsequent ticks reuse the
|
|
||||||
// localStorage cache — same idle-poll budget as before.
|
|
||||||
const seedHeadsIfMissing = async (threads: { _key: string }[]) => {
|
|
||||||
try {
|
|
||||||
const existing = JSON.parse(localStorage.getItem(`fm.canvas.chat.heads.${userEmail}`) || "{}");
|
|
||||||
if (Object.keys(existing).length >= threads.length) return;
|
|
||||||
} catch { /* fall through */ }
|
|
||||||
const { chatApi } = await import("./lib/chatApi");
|
|
||||||
const heads: Record<string, { at: string; by: string }> = {};
|
|
||||||
await Promise.all(
|
|
||||||
threads.map(async (t) => {
|
|
||||||
try {
|
|
||||||
const rows = await chatApi.listMessages(t._key);
|
|
||||||
const last = rows[rows.length - 1];
|
|
||||||
if (last) heads[t._key] = { at: last.created_at, by: last.author_email };
|
|
||||||
} catch { /* ignore */ }
|
|
||||||
})
|
|
||||||
);
|
|
||||||
try { localStorage.setItem(`fm.canvas.chat.heads.${userEmail}`, JSON.stringify(heads)); } catch { /* ignore */ }
|
|
||||||
};
|
|
||||||
const refresh = async () => {
|
const refresh = async () => {
|
||||||
try {
|
try {
|
||||||
const { chatApi } = await import("./lib/chatApi");
|
const { chatApi } = await import("./lib/chatApi");
|
||||||
@@ -133,8 +111,6 @@ export default function App() {
|
|||||||
apiMod.workItems().catch(() => []),
|
apiMod.workItems().catch(() => []),
|
||||||
]);
|
]);
|
||||||
if (cancelled) return;
|
if (cancelled) return;
|
||||||
await seedHeadsIfMissing(threads);
|
|
||||||
if (cancelled) return;
|
|
||||||
setChatUnreadCount(computeUnread(threads.map((t) => t._key)));
|
setChatUnreadCount(computeUnread(threads.map((t) => t._key)));
|
||||||
setQueueCount(items.filter((it) => (it as any).tenant_id === tenantId).length);
|
setQueueCount(items.filter((it) => (it as any).tenant_id === tenantId).length);
|
||||||
} catch { /* ignore */ }
|
} catch { /* ignore */ }
|
||||||
|
|||||||
Reference in New Issue
Block a user