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
7 changes: 5 additions & 2 deletions docs/development/PERFORMANCE_BASELINE.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@ inventory or catalog revision restarts paging. Free-text card search matches
all terms on each spool before grouping and paging. Typing refreshes the card
results independently of tab counts. Hosts without card-search support and
offline Clients use the full stock reader and the existing local filter.
Advanced filters, list view,
labels and selection use the complete stock so they cover every matching roll.
Current Hosts also filter individual rolls by status, ownership, material,
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. List view, labels and selection use the complete stock so they cover every matching roll.
A Client without a complete offline capture obtains one on its first full read.
Older Hosts and disconnected Clients use the existing full-list or scoped
offline path. Reading a card page preserves the last complete capture and its
Expand Down
30 changes: 27 additions & 3 deletions 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;
const delayedFilter = deferred();
const filterStarted = deferred();
const slowSearch = deferred();
const searchStarted = deferred();
const oldGeneration = deferred();
Expand Down Expand Up @@ -210,9 +212,11 @@ async function checkStockCards({page, state, fixture, calls, fallback, openWorks
return purchaseCount;
case "get_stock_card_page": {
assert.deepEqual(payload.target,target);
if (mode === "legacy" || (mode === "cards-only" && payload.query.search)) return null;
if (mode === "legacy" || (mode === "cards-only" && payload.query.search) || (mode === "search-only" && payload.query.filters)) return null;
if (mode === "offline") throw Error("[loan-regression] Host disconnected");
const {member_of,offset,search}=payload.query;
const {member_of,offset,search,filters}=payload.query;
const options = filters?.include_options ? {materials:["PLA","TPU"],vendors:["Generic","Rare vendor"]} : undefined;
if (filters?.vendor === "Rare vendor") { filterStarted.resolve(); return delayedFilter.promise; }
if (search === "generation") {
if (payload.target.target_generation === 3) { generationRead.resolve(); return oldGeneration.promise; }
return generationPage("Current generation");
Expand All @@ -226,7 +230,7 @@ async function checkStockCards({page, state, fixture, calls, fallback, openWorks
reads.push(offset);
const cards = offset === 1 && !member_of ? [{count:1,remaining:300,rows:[later]}] :
[{count:8,remaining:4000,rows:member_of ? members.slice(offset) : members.slice(0,3)}];
return {cards, total:10, visible:10, groups:3, borrowed:0, revisions:[revision,1]};
return {cards, options, total:10, visible:10, groups:3, borrowed:0, revisions:[revision,1]};
}
default: return fallback(command,payload);
}
Expand Down Expand Up @@ -262,6 +266,13 @@ async function checkStockCards({page, state, fixture, calls, fallback, openWorks
assert.equal(await panel.getByRole("heading",{name:/Hidden search match/}).count(),0);
assert.ok(!calls.some(c => ["fetch_library_sync_spool_snapshot","get_stock_purchase_count",
"fetch_library_sync_locations","fetch_library_sync_active_loans","fetch_library_sync_printer_overview"].includes(c.command)));
await page.getByRole("button",{name:"More filters", exact:true}).click();
await page.getByRole("button",{name:"Rare vendor", exact:true}).click();
await waitForStart(filterStarted);
await page.getByRole("button",{name:"Reset filters", exact:true}).click();
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("generation");
await waitForStart(generationRead);
Object.assign(status, {library_id:"cards-b", host_base_url:"https://cards-b.invalid", target_generation:4});
Expand All @@ -287,6 +298,11 @@ async function checkStockCards({page, state, fixture, calls, fallback, openWorks
await searchBox.fill("Hidden search match");
await panel.getByRole("heading",{name:/Hidden search match/}).waitFor();
await searchBox.fill("");
await page.getByRole("button",{name:"More filters",exact:true}).click();
await page.getByRole("button",{name:"Lost",exact:true}).click();
await panel.locator(".inventory-product-card").first().waitFor({state:"detached"});
await panel.getByRole("button",{name:"Reset filters",exact:true}).click();
await panel.getByRole("heading",{name:/Hidden search match/}).waitFor();
assert.equal(calls.filter(c => c.command === "fetch_library_sync_spool_snapshot").length, spoolReads);
}
assert.ok(calls.some(c=>c.command==="fetch_cached_library_sync_spools"));
Expand All @@ -295,6 +311,14 @@ async function checkStockCards({page, state, fixture, calls, fallback, openWorks
await page.getByRole("button", {name: "Refresh", exact: true}).click();
await expectBadges(page, {purchases: 2});
assert.ok(!calls.some(c => c.command === "get_purchase_queue_page"));
mode = "search-only";
await openWorkspace();
await page.locator("#inventory-stock-tab").click();
await panel.getByText(/8 spools/).waitFor();
calls.length = 0;
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"));
}

async function checkLegacyLocation({ page, state, fixture, calls, fallback, openWorkspace }) {
Expand Down
1 change: 1 addition & 0 deletions src-tauri/src/companion_library_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ pub(super) async fn handle_health(
LOAN_PICKER_CAPABILITY,
crate::companion_models::STOCK_CARDS_CAPABILITY,
crate::companion_models::STOCK_CARD_SEARCH_CAPABILITY,
crate::companion_models::STOCK_CARD_FILTER_CAPABILITY,
crate::companion_models::STOCK_PURCHASE_COUNT_CAPABILITY,
crate::companion_models::PURCHASE_QUEUE_CAPABILITY,
crate::companion_models::DASHBOARD_PURCHASE_CAPABILITY,
Expand Down
1 change: 1 addition & 0 deletions src-tauri/src/companion_models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ pub(crate) const CATALOG_SPOOL_BATCH_CAPABILITY: &str = "catalog-spool-batch-v1"
pub(crate) const LOAN_WORKSPACE_COUNTS: &str = "loan-workspace-counts-v1";
pub(crate) const STOCK_PURCHASE_COUNT_CAPABILITY: &str = "stock-purchase-count-v1";
pub(crate) const PURCHASE_QUEUE_CAPABILITY: &str = "purchase-queue-page-v1";
pub(crate) const STOCK_CARD_FILTER_CAPABILITY: &str = "stock-card-filters-v1";
pub(crate) const STOCK_CARD_SEARCH_CAPABILITY: &str = "stock-card-search-v1";
pub(crate) const STOCK_CARDS_CAPABILITY: &str = "stock-cards-v1";
pub(crate) const DASHBOARD_PURCHASE_CAPABILITY: &str = "dashboard-purchase-v1";
Expand Down
23 changes: 21 additions & 2 deletions src-tauri/src/library_sync_read_commands/tests/stock_cards.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,38 @@
use super::{fake_health, fake_host_state, spawn_fake_host_with, FakeHostResponse};
use crate::{
backend::{database_stock_cards::StockCardQuery, filament_database::FilamentDatabase},
companion_models::{STOCK_CARDS_CAPABILITY, STOCK_CARD_SEARCH_CAPABILITY},
companion_models::{
STOCK_CARDS_CAPABILITY, STOCK_CARD_FILTER_CAPABILITY, STOCK_CARD_SEARCH_CAPABILITY,
},
spool_picker_commands::stock_card_page_blocking,
};
use serde_json::json;

#[test]
fn stock_card_pages_distinguish_old_hosts_and_offline_and_reject_late_a_b_a_reads() {
check_card_target(false);
}

#[test]
fn filtered_stock_cards_fall_back_on_search_only_hosts_and_reject_a_b_a() {
check_card_target(true);
}

fn check_card_target(filter: bool) {
const POST: &str = "POST /api/v1/library/stock-cards ";
let health = |modern| {
let mut body: serde_json::Value = serde_json::from_str(&fake_health()).unwrap();
body["capabilities"] = json!([STOCK_CARDS_CAPABILITY]);
if modern {
if filter {
body["capabilities"] = json!([STOCK_CARDS_CAPABILITY, STOCK_CARD_SEARCH_CAPABILITY]);
}
if modern {
body["capabilities"] = json!([
STOCK_CARDS_CAPABILITY,
STOCK_CARD_SEARCH_CAPABILITY,
STOCK_CARD_FILTER_CAPABILITY
]);
}
FakeHostResponse {
expected_request_prefix: "GET /api/v1/health ",
status: "200 OK",
Expand Down Expand Up @@ -56,6 +74,7 @@ fn stock_card_pages_distinguish_old_hosts_and_offline_and_reject_late_a_b_a_read
let db = FilamentDatabase::open(&path).unwrap();
let initial = db.get_library_sync_page_status().unwrap().target_generation;
let query = || StockCardQuery {
filters: filter.then(Default::default),
member_of: None,
locale: None,
offset: 100,
Expand Down
4 changes: 3 additions & 1 deletion src-tauri/src/spool_picker_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,9 @@ pub(crate) fn stock_card_page_blocking(
state,
&query,
target,
if query.search.trim().is_empty() {
if query.filters.is_some() {
crate::companion_models::STOCK_CARD_FILTER_CAPABILITY
} else if query.search.trim().is_empty() {
crate::companion_models::STOCK_CARDS_CAPABILITY
} else {
crate::companion_models::STOCK_CARD_SEARCH_CAPABILITY
Expand Down
Loading
Loading