From edfb079bb11acda87a6a50ac65c7b34243607643 Mon Sep 17 00:00:00 2001 From: vikingowl Date: Sun, 29 Mar 2026 20:41:56 +0200 Subject: [PATCH] perf(frecency): remove blocking auto-save on every launch record_launch no longer calls save() synchronously. The dirty flag is set and the Drop impl flushes on shutdown. Removes a JSON serialize + fs::write from the hot launch path. --- crates/owlry-core/src/data/frecency.rs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/crates/owlry-core/src/data/frecency.rs b/crates/owlry-core/src/data/frecency.rs index c968939..13238d2 100644 --- a/crates/owlry-core/src/data/frecency.rs +++ b/crates/owlry-core/src/data/frecency.rs @@ -115,11 +115,6 @@ impl FrecencyStore { "Recorded launch for '{}': count={}, last={}", item_id, entry.launch_count, entry.last_launch ); - - // Auto-save after recording - if let Err(e) = self.save() { - warn!("Failed to save frecency data: {}", e); - } } /// Calculate frecency score for an item @@ -255,4 +250,18 @@ mod tests { assert!(score_many > score_few); assert!((score_many / score_few - 10.0).abs() < 0.1); // Should be ~10x } + + #[test] + fn record_launch_sets_dirty_without_saving() { + let mut store = FrecencyStore { + data: FrecencyData::default(), + path: PathBuf::from("/dev/null"), + dirty: false, + }; + + store.record_launch("test-item"); + + assert!(store.dirty, "record_launch should set dirty flag"); + assert_eq!(store.data.entries["test-item"].launch_count, 1); + } }