Skip to content

Feature/persistent scan cache - #1

Open
abdelmalek-baati wants to merge 2 commits into
phantekzy:mainfrom
abdelmalek-baati:feature/persistent-scan-cache
Open

Feature/persistent scan cache#1
abdelmalek-baati wants to merge 2 commits into
phantekzy:mainfrom
abdelmalek-baati:feature/persistent-scan-cache

Conversation

@abdelmalek-baati

Copy link
Copy Markdown

Caches scan results to disk so previously-scanned folders load instantly on the next run, while a fresh scan updates the view in the background. Old cache entries are pruned automatically after 14 days.

Copilot AI lite review requested due to automatic review settings August 5, 2026 00:46

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a persistent on-disk cache for directory scan results so the UI can start instantly from a previous scan, while a fresh scan updates the view in the background. Cache entries are automatically pruned after 14 days.

Changes:

  • Introduces a new cache module to serialize/deserialize scan trees and prune stale entries.
  • Updates main/run to load cached results on startup and kick off a background rescan, saving fresh results back to disk.
  • Updates crate metadata/dependencies to support caching (serde/bincode/dirs) and renames the binary to kenshi.

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 5 comments.

File Description
src/main.rs Loads cached scan trees, spawns background rescan, and persists fresh scans back to disk.
src/cache.rs Implements cache directory selection, cache keying, save/load, and stale-entry pruning.
Cargo.toml Renames the binary target and adds dependencies needed for cache serialization/storage.
Cargo.lock Locks new transitive dependencies introduced by caching-related crates.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/main.rs
Comment on lines +109 to +118
// Pick up a completed background scan, if one is pending.
if let Some(receiver) = &rx {
if let Ok(fresh) = receiver.try_recv() {
let _ = cache::save(scan_path, &fresh);
let loaded_from_cache = app.status.is_some();
*app = App::new(fresh);
if loaded_from_cache {
app.status = Some("Loaded cached view - rescan complete".to_string());
}
rx = None;
Comment thread src/main.rs
Comment on lines 140 to 146
KeyCode::Char('r') => {
app.status = Some("rescanning...".to_string());
terminal.draw(|f| ui::draw(f, app, &mut list_state))?;
let root = DirNode::scan(scan_path);
let _ = cache::save(scan_path, &root);
*app = App::new(root);
}
Comment thread src/cache.rs
Comment on lines +76 to +87
pub fn load(scan_path: &Path) -> Option<DirNode> {
let file = cache_file_for(scan_path);
let meta = std::fs::metadata(&file).ok()?;
let age = meta.modified().ok()?.elapsed().ok()?;
if age > CACHE_TTL {
let _ = std::fs::remove_file(&file);
return None;
}
let bytes = std::fs::read(&file).ok()?;
let cached: CachedNode = bincode::deserialize(&bytes).ok()?;
Some(cached.into_dir_node())
}
Comment thread src/cache.rs
Comment on lines +89 to +96
pub fn save(scan_path: &Path, root: &DirNode) -> io::Result<()> {
let dir = cache_dir();
std::fs::create_dir_all(&dir)?;
let cached = CachedNode::from(root);
let bytes =
bincode::serialize(&cached).map_err(|e| io::Error::new(io::ErrorKind::Other, e))?;
std::fs::write(cache_file_for(scan_path), bytes)
}
Comment thread Cargo.toml
Comment on lines +27 to +30
blake3 = "1"
serde = { version = "1", features = ["derive"] }
bincode = "1.3"
dirs = "5"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants