Manage the KV cache disc usage from preferences and stats
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -132,7 +132,12 @@ impl App {
|
||||
pub(super) fn reload_projects(&mut self) {
|
||||
if let Some(database) = &mut self.database {
|
||||
match database.load_projects() {
|
||||
Ok(projects) => self.projects = projects,
|
||||
Ok(projects) => {
|
||||
self.projects = projects;
|
||||
if super::sweep_orphan_checkpoints(&super::kv_cache_path(), &self.projects) {
|
||||
self.finish_cache_change();
|
||||
}
|
||||
}
|
||||
Err(error) => self.error = Some(error),
|
||||
}
|
||||
}
|
||||
@@ -190,6 +195,36 @@ mod tests {
|
||||
assert_eq!(draft_title(&projects, 99), "Session 1");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sweeping_removes_checkpoints_of_sessions_that_no_longer_exist() {
|
||||
let directory =
|
||||
std::env::temp_dir().join(format!("ds4-server-sweep-{}", std::process::id()));
|
||||
std::fs::create_dir_all(&directory).unwrap();
|
||||
for name in ["1.bin", "2.bin", "notes.bin", "7.bin"] {
|
||||
std::fs::write(directory.join(name), b"payload").unwrap();
|
||||
}
|
||||
let projects = vec![ProjectWithSessions {
|
||||
project: project(1, "First"),
|
||||
sessions: vec![session(1, 1), session(2, 1)],
|
||||
}];
|
||||
|
||||
assert!(super::super::sweep_orphan_checkpoints(
|
||||
&directory, &projects
|
||||
));
|
||||
|
||||
assert!(directory.join("1.bin").exists());
|
||||
assert!(directory.join("2.bin").exists());
|
||||
// Not a session checkpoint, so not ours to delete.
|
||||
assert!(directory.join("notes.bin").exists());
|
||||
assert!(!directory.join("7.bin").exists());
|
||||
// Nothing left to sweep on the next pass.
|
||||
assert!(!super::super::sweep_orphan_checkpoints(
|
||||
&directory, &projects
|
||||
));
|
||||
|
||||
std::fs::remove_dir_all(directory).unwrap();
|
||||
}
|
||||
|
||||
fn project(id: i32, name: &str) -> Project {
|
||||
Project {
|
||||
id,
|
||||
|
||||
Reference in New Issue
Block a user