Feature/persistent scan cache - #1
Open
abdelmalek-baati wants to merge 2 commits into
Open
Conversation
There was a problem hiding this comment.
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
cachemodule to serialize/deserialize scan trees and prune stale entries. - Updates
main/runto 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 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 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 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 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 on lines
+27
to
+30
| blake3 = "1" | ||
| serde = { version = "1", features = ["derive"] } | ||
| bincode = "1.3" | ||
| dirs = "5" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.