Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/development/PERFORMANCE_BASELINE.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ vendor, location and low-stock policy before grouping. Opening the filter panel
requests distinct materials and vendors from the whole stock in the same read
transaction. Older Hosts and offline Clients filter the complete live or saved
list. Open inventory from a linked shelf passes the location and search text
to the first card-page read. Opening an individual shelf roll still checks its
to the first card-page read. Returning to a filtered card view in the same
library and refreshing a local card view reuse the active search and filters. Opening an individual shelf roll still checks its
placement against stock from the reviewed library and generation.
Opening and closing Add spool keeps the loaded cards and reads the
registration catalog on demand. A successful registration refreshes stock
Expand Down
37 changes: 36 additions & 1 deletion scripts/run-loan-dialog-regressions.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ async function checkStockCards({page, state, fixture, calls, fallback, openWorks
let mode = "live";
let revision = 1;
let purchaseCount = 1;
let searchedRoll = hidden;
let failLocalPrinters = false;
const delayedFilter = deferred();
const filterStarted = deferred();
const slowSearch = deferred();
Expand All @@ -194,6 +196,9 @@ async function checkStockCards({page, state, fixture, calls, fallback, openWorks
});
state.invoke = (command,payload) => {
switch (command) {
case "list_printer_overview":
if (failLocalPrinters) throw Error("[loan-regression] Local printer read interrupted");
return [];
case "get_library_sync_page_status": return status;
case "fetch_library_sync_catalog_masters": return fixture.catalogRows;
case "get_loan_workspace_counts": return {stock:10, locations:0, loans:2, purchases:0};
Expand Down Expand Up @@ -225,7 +230,7 @@ async function checkStockCards({page, state, fixture, calls, fallback, openWorks
if (search === "slow") { searchStarted.resolve(); return slowSearch.promise; }
if (search) {
const hit = search === "Hidden search match";
return {cards:hit ? [{count:1,remaining:300,rows:[hidden]}] : [],
return {cards:hit ? [{count:1,remaining:300,rows:[searchedRoll]}] : [],
total:10, visible:Number(hit), groups:Number(hit), borrowed:0, revisions:[revision,1]};
}
reads.push(offset);
Expand Down Expand Up @@ -281,6 +286,18 @@ async function checkStockCards({page, state, fixture, calls, fallback, openWorks
delayedFilter.resolve({cards:[],total:10, visible:0, groups:0, borrowed:0, revisions:[revision,1]});
await panel.getByText(/8 spools/).waitFor();
assert.ok(!calls.some(c => c.command === "fetch_library_sync_spool_snapshot" || c.command === "get_stock_purchase_count"));
await searchBox.fill("Hidden search match");
await panel.getByRole("heading", {name: /Hidden search match/}).waitFor();
await page.locator("#inventory-locations-tab").click();
await page.locator("#inventory-locations-panel").waitFor();
searchedRoll = {...hidden, master: {...hidden.master, filament_name: "Updated hidden search match"}};
calls.length = 0;
await page.locator("#inventory-stock-tab").click();
await panel.getByRole("heading", {name: /Updated hidden search match/}).waitFor();
const returnedPages = calls.filter(call => call.command === "get_stock_card_page");
assert.deepEqual(returnedPages.map(call => call.payload.query.search), ["Hidden search match"]);
assert.ok(returnedPages[0].payload.query.filters.include_options);
assert.ok(!calls.some(call => call.command === "fetch_library_sync_spool_snapshot"));
await searchBox.fill("generation");
await waitForStart(generationRead);
Object.assign(status, {library_id:"cards-b", host_base_url:"https://cards-b.invalid", target_generation:4});
Expand Down Expand Up @@ -327,6 +344,24 @@ async function checkStockCards({page, state, fixture, calls, fallback, openWorks
await page.getByRole("button",{name:"More filters",exact:true}).click();
await panel.getByRole("heading",{name:/Hidden search match/}).waitFor();
assert.ok(calls.some(c => c.command === "fetch_library_sync_spool_snapshot"));

mode = "live";
Object.assign(status, {mode: "STANDALONE", host_base_url: null, client_auth_paired: false});
target.base_url = null;
failLocalPrinters = true;
await openWorkspace();
await page.locator("#inventory-stock-tab").click();
await panel.getByText(/8 spools/).waitFor();
await searchBox.fill("Hidden search match");
await panel.getByRole("heading", {name: /Updated hidden search match/}).waitFor();
failLocalPrinters = false;
searchedRoll = {...hidden, master: {...hidden.master, filament_name: "Refreshed hidden search match"}};
calls.length = 0;
await page.getByRole("button", {name: "Refresh", exact: true}).click();
await panel.getByRole("heading", {name: /Refreshed hidden search match/}).waitFor();
assert.deepEqual(calls.filter(call => call.command === "get_stock_card_page")
.map(call => call.payload.query.search), ["Hidden search match"]);
assert.ok(!calls.some(call => call.command === "list_spools"));
}

async function checkLegacyLocation({ page, state, fixture, calls, fallback, openWorkspace }) {
Expand Down
20 changes: 13 additions & 7 deletions ui/src/pages/inventory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -418,10 +418,14 @@ export default function InventoryPage({
} : undefined, [advancedFiltersOpen, otherFilterCount, statusFilter, ownershipFilter, materialFilter,
vendorFilter, locationFilter?.id, lowStockOnly]);
const cardSearch = search.trim();
const stockViewRef = useRef({ requestCards, search: cardSearch, filters: cardFilters });
const cardRequest = useMemo(() => requestCards && (
cardSearch || cardFilters ? { search: cardSearch, filters: cardFilters } : true
), [requestCards, cardSearch, cardFilters]);
const hasCardPage = cardPage != null;
const stockViewRef = useRef({ cardRequest, hasCardPage });
useEffect(() => {
stockViewRef.current = { requestCards, search: cardSearch, filters: cardFilters };
}, [requestCards, cardSearch, cardFilters]);
stockViewRef.current = { cardRequest, hasCardPage };
}, [cardRequest, hasCardPage]);
const lastCardSearchAt = useRef(-Infinity);
const pendingCardSearch = requestCards && cardPage != null && (cardPage.search !== cardSearch || cardPage.filters !== cardFilters);
const loadingLocationStock = Boolean(locationFilter && (loading || refreshing));
Expand All @@ -448,8 +452,10 @@ export default function InventoryPage({
if (!tauri || !librarySyncReady || pendingPurchaseNavigation || loansOnly || pendingLoanNavigation) return;
let current = true;
const handoff = pendingLocationStock.current;
const { requestCards: useCards, search, filters } = stockViewRef.current;
const cardPage = useCards && !handoff?.spoolId && (handoff ? { search, filters } : true);
const view = stockViewRef.current;
// A retained card page belongs to the current library. A new target starts
// fresh unless the user explicitly opened its shelf.
const cardPage = !handoff?.spoolId && (handoff || view.hasCardPage ? view.cardRequest : Boolean(view.cardRequest));
void refreshInventoryData({ purchasesOnly, locationsOnly, cardPage, onStockLoaded: handoff ? async rows => {
if (!current || pendingLocationStock.current !== handoff) return;
try {
Expand Down Expand Up @@ -483,10 +489,10 @@ export default function InventoryPage({
if (loansOnly) return;
void refreshInventoryData({
// Explicit Client refresh also renews the complete offline inventory.
purchasesOnly, locationsOnly, cardPage: requestCards && !clientReadOnly,
purchasesOnly, locationsOnly, cardPage: !clientReadOnly && cardRequest,
selectedSpoolId: showRollModal ? selectedSpoolId : null,
});
}, [requestCards, clientReadOnly, loansOnly, purchasesOnly, locationsOnly, refreshInventoryData, selectedSpoolId, showRollModal]);
}, [cardRequest, clientReadOnly, loansOnly, purchasesOnly, locationsOnly, refreshInventoryData, selectedSpoolId, showRollModal]);

const retryInventoryPageLoad = useCallback(() => {
if (!librarySyncReady) {
Expand Down
Loading