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
5 changes: 5 additions & 0 deletions docs/development/QUALITY_GATES.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ Tests complete requests out of order with equal Host
timestamps and exercise the fallback for older Hosts. API tests cover legacy loan directions, returned
loans, deleted spools and unreadable fields outside the response.

Stock and Purchases keep the Host's total alongside the visited purchase rows.
Offline pagination and search cover saved rows, while the tab badge uses the
captured total. Older snapshots fall back to their saved row count until a
successful Host refresh supplies the total.

Paired printer overview reads share one publication order across page loads,
post-write refreshes and printer onboarding confirmation. Native tests delay a
reply while a later request starts, publishes, or the pairing switches A–B–A,
Expand Down
5 changes: 5 additions & 0 deletions scripts/run-loan-dialog-regressions.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,11 @@ async function checkStockCards({page, state, fixture, calls, fallback, openWorks
return {rows:cachedMembers,captured_at:"2026-01-01"};
case "get_stock_purchase_count":
assert.deepEqual(payload.target,target);
if (mode === "offline") throw Error("[loan-regression] Host disconnected");
return purchaseCount;
case "fetch_cached_library_sync_wishlist":
assert.deepEqual(payload.input, target);
return { captured_at: "2026-01-01", total: 502, rows: fixture.wishlistRows.slice(0, 1) };
case "get_stock_card_page": {
assert.deepEqual(payload.target,target);
if (mode === "legacy" || (mode === "cards-only" && payload.query.search) || (mode === "search-only" && payload.query.filters)) return null;
Expand Down Expand Up @@ -509,6 +513,7 @@ async function checkStockCards({page, state, fixture, calls, fallback, openWorks
await panel.getByRole("heading",{name:/Hidden search match/}).waitFor();
assert.equal(calls.filter(c => c.command === "fetch_library_sync_spool_snapshot").length, spoolReads);
if (mode === "offline") {
await expectBadges(page, {purchases: 502});
const cachedMenu = panel.locator(".inventory-product-menu");
const summary = cachedMenu.locator("summary");
const rollButtons = cachedMenu.getByRole("button", {name: /Open roll/});
Expand Down
1 change: 1 addition & 0 deletions src-tauri/src/library_sync_cache_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ pub(crate) fn fetch_cached_library_sync_wishlist_blocking(
Ok(settings
.cached_wishlist
.map(|cached| LibrarySyncCachedWishlistList {
total: cached.total,
captured_at: cached.captured_at,
rows: cached.rows,
}))
Expand Down
2 changes: 2 additions & 0 deletions src-tauri/src/library_sync_models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,8 @@ pub(crate) use crate::backend::database_library_sync_models::LibrarySyncCachedLo

#[derive(Serialize, Deserialize, Clone)]
pub(crate) struct LibrarySyncCachedWishlistList {
#[serde(skip_serializing_if = "Option::is_none")]
pub(crate) total: Option<i64>,
pub(crate) captured_at: String,
pub(crate) rows: Vec<WishlistItemRow>,
}
1 change: 1 addition & 0 deletions src/backend/database_library_sync_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ pub(crate) fn save_library_sync_cached_wishlist(
rows: &[WishlistItemRow],
) -> InventoryResult<()> {
let payload = LibrarySyncCachedWishlistListRow {
total: None,
captured_at: sqlite_now(conn)?,
rows: rows.to_vec(),
};
Expand Down
2 changes: 2 additions & 0 deletions src/backend/database_library_sync_models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ pub struct LibrarySyncCachedFilamentConsumptionListRow {

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct LibrarySyncCachedWishlistListRow {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub total: Option<i64>,
pub captured_at: String,
pub rows: Vec<WishlistItemRow>,
}
Expand Down
7 changes: 5 additions & 2 deletions src/backend/database_loan_workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,11 @@ impl FilamentDatabase {
locations: self.reduce_cached_rows("library_sync_cached_locations_json",
"SELECT count(*) FROM json_each((SELECT rows FROM valid_cache)) WHERE upper(trim(value ->> '$.location_type')) IN ('GENERIC','SHELF')
AND coalesce(value ->> '$.archived_at','') = ''", |r| r.get(0))?,
purchases: self.reduce_cached_rows("library_sync_cached_wishlist_json",
"SELECT json_array_length((SELECT rows FROM valid_cache))", |r| r.get(0))?,
purchases: self.connection().query_row(
"SELECT CASE WHEN json_valid(value) THEN CASE WHEN json_type(value,'$.rows')='array'
THEN coalesce(json_extract(value,'$.total'),json_array_length(value,'$.rows')) END END
FROM settings WHERE key='library_sync_cached_wishlist_json'", [], |row| row.get(0),
).optional()?.flatten(),
};
if counts != LoanWorkspaceCounts::default() {
self.save_loan_workspace_counts(&counts)?;
Expand Down
41 changes: 35 additions & 6 deletions src/backend/database_wishlist_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl FilamentDatabase {
pub fn cached_stock_purchase_revision(&self) -> InventoryResult<Option<i64>> {
Ok(self.connection().query_row(
"SELECT CASE WHEN json_valid(value) THEN CASE WHEN json_extract(value,'$.stock_page')=1
AND json_type(value,'$.rows')='array' THEN json_extract(value,'$.revision') END END
AND json_type(value,'$.rows')='array' AND json_type(value,'$.total')='integer' THEN json_extract(value,'$.revision') END END
FROM settings WHERE key='library_sync_cached_wishlist_json'", [], |row| row.get(0),
).optional()?.flatten())
}
Expand Down Expand Up @@ -132,6 +132,7 @@ struct CachedQueue {
#[serde(default)]
stock_page: bool,
revision: Option<i64>,
total: Option<i64>,
captured_at: String,
rows: Vec<WishlistItemRow>,
}
Expand Down Expand Up @@ -179,6 +180,7 @@ impl FilamentDatabase {
let cached = CachedQueue {
stock_page,
revision: Some(revision),
total: Some(total),
captured_at: db.sqlite_now()?,
rows,
};
Expand All @@ -203,13 +205,27 @@ mod tests {
})
.unwrap()
};
db.set_setting(
"library_sync_cached_wishlist_json",
r#"{"captured_at":"old","revision":0,"stock_page":true,"rows":[]}"#,
)
.unwrap();
assert_eq!(db.cached_stock_purchase_revision().unwrap(), None);
let empty = read();
assert_eq!(empty.total, 0);
let rows = empty.rows.unwrap();
assert!(rows.is_empty());
db.cache_purchase_rows(&rows, 0, empty.revision, true)
.unwrap();
assert!(read().rows.is_none());
assert_eq!(
db.get_library_sync_settings()
.unwrap()
.cached_wishlist
.unwrap()
.total,
Some(0)
);

db.connection()
.execute_batch(
Expand All @@ -220,7 +236,14 @@ mod tests {
.unwrap();
let changed = read();
assert_eq!(changed.total, 51);
assert_eq!(changed.rows.unwrap().len(), 50);
let rows = changed.rows.unwrap();
assert_eq!(rows.len(), 50);
db.cache_purchase_rows(&rows, changed.total, changed.revision, true)
.unwrap();
assert_eq!(
db.cached_loan_workspace_counts().unwrap().purchases,
Some(51)
);
}

#[test]
Expand Down Expand Up @@ -249,6 +272,12 @@ mod tests {
);
assert_eq!(order.rows[0].id, "old");
db.cache_purchase_queue_page(&order).unwrap();
let partial = db
.get_library_sync_settings()
.unwrap()
.cached_wishlist
.unwrap();
assert_eq!((partial.total, partial.rows.len()), (Some(502), 1));
query.status = "ALL".into();
query.search.clear();
query.reviewed_item_id = Some("old".into());
Expand Down Expand Up @@ -291,12 +320,12 @@ mod tests {
assert_eq!((empty.offset, empty.matched), (0, 0));
db.cache_purchase_queue_page(&empty).unwrap();
db.cache_purchase_queue_page(&first).unwrap();
assert!(db
let saved = db
.get_library_sync_settings()
.unwrap()
.cached_wishlist
.unwrap()
.rows
.is_empty());
.unwrap();
assert!(saved.rows.is_empty());
assert_eq!(saved.total, Some(0));
}
}
2 changes: 1 addition & 1 deletion ui/src/lib/purchase_queue_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export async function loadPurchaseQueuePage(
if (!target.base_url) throw error;
const cached = await fetchCachedLibrarySyncWishlist(target.base_url, target.expected_library_id, target.target_generation).catch(() => null);
const page = pageOfSavedRows(cached?.rows ?? [], query, options.reviewedItemId);
return { rows: page.rows, page, source: cached ? "CACHED" as const : "OFFLINE" as const };
return { rows: page.rows, page, total: cached?.total, source: cached ? "CACHED" as const : "OFFLINE" as const };
}
const legacy = await loadWishlistItemsSnapshot(options);
const page = pageOfSavedRows(legacy.rows, query, options.reviewedItemId);
Expand Down
1 change: 1 addition & 0 deletions ui/src/lib/tauri_library_sync_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ export type LibrarySyncCachedFilamentConsumptionList = {
};

export type LibrarySyncCachedWishlistList = {
total?: number;
captured_at: string;
rows: WishlistItemRow[];
};
Expand Down
Loading