diff --git a/docs/development/PERFORMANCE_BASELINE.md b/docs/development/PERFORMANCE_BASELINE.md
index 224510f2..1dff90e4 100644
--- a/docs/development/PERFORMANCE_BASELINE.md
+++ b/docs/development/PERFORMANCE_BASELINE.md
@@ -173,7 +173,10 @@ before pagination. The search field updates immediately and requests a page afte
immediately. A Dashboard handoff sorts the acknowledged order first
within the selected filter. Each response reads totals and rows from one
SQLite snapshot. Older Hosts use their existing recent list. Offline search
-and counts use only saved rows. The Client retains up to 500 visited rows from
+and counts use only saved rows. The Purchases fallback reads the saved wishlist.
+The active Loans fallback reads the saved active list, including an empty one,
+and uses saved loan history only when the active list is missing.
+The Client retains up to 500 visited purchase rows from
the same wishlist revision and rejects pages from an obsolete pairing.
Inventory and Purchases read the default purchase currency in the background.
diff --git a/src-tauri/src/library_sync_cache_commands.rs b/src-tauri/src/library_sync_cache_commands.rs
index 439cb5c3..c106371f 100644
--- a/src-tauri/src/library_sync_cache_commands.rs
+++ b/src-tauri/src/library_sync_cache_commands.rs
@@ -155,6 +155,48 @@ mod tests {
std::fs::remove_file(path).unwrap();
}
+ #[test]
+ fn purchase_and_active_loan_caches_are_independent_of_spools_and_each_other() {
+ let (state, path, input) = client_state();
+ let db = FilamentDatabase::open(&path).unwrap();
+ let poison = |key| {
+ db.connection()
+ .execute(
+ "INSERT OR REPLACE INTO settings (key, value) VALUES (?1, X'FF')",
+ [key],
+ )
+ .unwrap();
+ };
+ let purchases = || super::fetch_cached_library_sync_wishlist_blocking(&state, &input);
+ let loans = || super::fetch_cached_library_sync_active_loans_blocking(&state, &input);
+ let wishlist = "library_sync_cached_wishlist_json";
+ let active = "library_sync_cached_active_loans_json";
+ let history = "library_sync_cached_loans_json";
+ poison("library_sync_cached_spools_json");
+ assert!(purchases().unwrap().is_none());
+ assert!(loans().unwrap().is_none());
+
+ poison(history);
+ poison(active);
+ db.set_setting(wishlist, r#"{"captured_at":"purchase","rows":[{"id":"order","vendor":"Test","material":"PLA","filament_name":"Basic","color_name":"White","status":"ON_ORDER","quantity":7,"created_at":"","updated_at":""}]}"#).unwrap();
+ let saved = purchases().unwrap().unwrap();
+ assert_eq!(saved.captured_at, "purchase");
+ assert_eq!(saved.rows[0].quantity, 7);
+
+ poison(wishlist);
+ db.set_setting(active, r#"{"captured_at":"active","rows":[]}"#)
+ .unwrap();
+ assert_eq!(loans().unwrap().unwrap().captured_at, "active");
+ db.connection()
+ .execute("DELETE FROM settings WHERE key=?1", [active])
+ .unwrap();
+ db.set_setting(history, r#"{"captured_at":"legacy","rows":[]}"#)
+ .unwrap();
+ assert_eq!(loans().unwrap().unwrap().captured_at, "legacy");
+ drop(db);
+ std::fs::remove_file(path).unwrap();
+ }
+
#[test]
fn cached_read_rejects_a_to_b_target_switch() {
let (state, db_path, input) = client_state();
@@ -172,6 +214,8 @@ mod tests {
fetch_cached_library_sync_spools_blocking(&state, &input).is_err(),
"target A fallback must not read target B cache",
);
+ assert!(super::fetch_cached_library_sync_wishlist_blocking(&state, &input).is_err());
+ assert!(super::fetch_cached_library_sync_active_loans_blocking(&state, &input).is_err());
let _ = std::fs::remove_file(db_path);
}
@@ -200,6 +244,8 @@ mod tests {
fetch_cached_library_sync_spools_blocking(&state, &input).is_err(),
"old target A generation must not read replacement A cache",
);
+ assert!(super::fetch_cached_library_sync_wishlist_blocking(&state, &input).is_err());
+ assert!(super::fetch_cached_library_sync_active_loans_blocking(&state, &input).is_err());
let _ = std::fs::remove_file(db_path);
}
}
@@ -285,7 +331,8 @@ pub(crate) fn fetch_cached_library_sync_active_loans_blocking(
) -> Result