fix(catalog): keep the live catalog truthful after every import path
The live catalog store only covered part of the import surface. A durable job settled, a sync queue drained, a .nitro upload or a clone run left the Studio rail and the stats bar showing pre-import numbers until the page was reloaded, and the Catalog Manager kept a second tree that never saw writes made elsewhere in the session. Every one of those paths now pulls the tree again, and the refresh carries the totals with it: importing writes catalog rows server-side, so the counts the store holds were stale for the rest of the session. - refreshCatalogTree shares one request between concurrent callers and queues a single follow-up read when a write lands mid-flight, so a burst of edits costs at most one extra read. - useFurnitureJobs treats its first payload as a baseline, so a page load no longer replays every past import as "just settled", and hands the settled jobs to the callback. - The Catalog Manager pushes its own mutations into the store and re-reads its active tab when the store changes. - The 30s unstable_cache on the admin totals is now tagged and invalidated from every catalog write, including the import worker, so it no longer survives an import even across a hard reload. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
d73baf1458
commit
28ce0f911c
@@ -7,6 +7,7 @@ import {
|
||||
type CreatedCatalogPage,
|
||||
EMPTY_CATALOG_DELTA,
|
||||
isEmptyCatalogDelta,
|
||||
normalizeCatalogTotals,
|
||||
normalizeTreePages,
|
||||
recomputeDepth,
|
||||
} from "./live-catalog-merge";
|
||||
@@ -238,3 +239,41 @@ describe("isEmptyCatalogDelta", () => {
|
||||
expect(isEmptyCatalogDelta(EMPTY_CATALOG_DELTA)).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("normalizeCatalogTotals", () => {
|
||||
it("accepts a totals payload from the tree route", () => {
|
||||
expect(
|
||||
normalizeCatalogTotals({
|
||||
totalPages: 12,
|
||||
enabledPages: 9,
|
||||
totalItems: 400,
|
||||
}),
|
||||
).toEqual({ totalPages: 12, enabledPages: 9, totalItems: 400 });
|
||||
});
|
||||
|
||||
it("coerces string counts the way MariaDB drivers return them", () => {
|
||||
expect(
|
||||
normalizeCatalogTotals({
|
||||
totalPages: "12",
|
||||
enabledPages: "9",
|
||||
totalItems: "400",
|
||||
}),
|
||||
).toEqual({ totalPages: 12, enabledPages: 9, totalItems: 400 });
|
||||
});
|
||||
|
||||
it("accepts an explicit zeroed payload for an empty catalog", () => {
|
||||
expect(
|
||||
normalizeCatalogTotals({
|
||||
totalPages: 0,
|
||||
enabledPages: 0,
|
||||
totalItems: 0,
|
||||
}),
|
||||
).toEqual({ totalPages: 0, enabledPages: 0, totalItems: 0 });
|
||||
});
|
||||
|
||||
it("rejects a missing or partial payload so the store keeps its counts", () => {
|
||||
expect(normalizeCatalogTotals(undefined)).toBeNull();
|
||||
expect(normalizeCatalogTotals("nope")).toBeNull();
|
||||
expect(normalizeCatalogTotals({ totalPages: 3 })).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user