Discard archived session checkpoints
This commit is contained in:
58
src/app.rs
58
src/app.rs
@@ -1757,11 +1757,19 @@ impl App {
|
||||
.collect::<Vec<_>>()
|
||||
})
|
||||
.unwrap_or_default();
|
||||
for session_id in &checkpoint_ids {
|
||||
if let Err(error) =
|
||||
discard_session_checkpoint_files(&kv_cache_path(), *session_id)
|
||||
{
|
||||
self.error = Some(error);
|
||||
return Task::none();
|
||||
}
|
||||
}
|
||||
self.finish_cache_change();
|
||||
if let Some(database) = &mut self.database {
|
||||
match database.delete_project(project_id) {
|
||||
Ok(()) => {
|
||||
for session_id in checkpoint_ids {
|
||||
let _ = fs::remove_file(session_checkpoint_path(session_id));
|
||||
#[cfg(target_os = "macos")]
|
||||
self.background_chats.remove(&session_id);
|
||||
}
|
||||
@@ -1902,22 +1910,33 @@ impl App {
|
||||
self.error =
|
||||
Some("Stop the active generation before rebuilding context.".into());
|
||||
} else {
|
||||
match fs::remove_file(session_checkpoint_path(session_id)) {
|
||||
Ok(()) => {
|
||||
match discard_session_checkpoint_files(&kv_cache_path(), session_id) {
|
||||
Ok(_) => {
|
||||
self.error = None;
|
||||
self.finish_cache_change();
|
||||
}
|
||||
Err(error) if error.kind() == std::io::ErrorKind::NotFound => {
|
||||
self.error = None;
|
||||
}
|
||||
Err(error) => {
|
||||
self.error = Some(format!("Could not discard the checkpoint: {error}"));
|
||||
self.error = Some(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Message::SetSessionState(session_id, state) => {
|
||||
self.session_menu = None;
|
||||
if state == SessionState::Archived {
|
||||
if self.session_is_active(session_id) {
|
||||
self.error =
|
||||
Some("Stop the active generation before archiving its session.".into());
|
||||
return Task::none();
|
||||
}
|
||||
if let Err(error) =
|
||||
discard_session_checkpoint_files(&kv_cache_path(), session_id)
|
||||
{
|
||||
self.error = Some(error);
|
||||
return Task::none();
|
||||
}
|
||||
self.finish_cache_change();
|
||||
}
|
||||
if let Some(database) = &mut self.database {
|
||||
match database.set_session_state(session_id, state) {
|
||||
Ok(()) => {
|
||||
@@ -2047,13 +2066,16 @@ impl App {
|
||||
Some("Stop the active generation before deleting its session.".into());
|
||||
return Task::none();
|
||||
}
|
||||
if let Err(error) = discard_session_checkpoint_files(&kv_cache_path(), session_id) {
|
||||
self.error = Some(error);
|
||||
return Task::none();
|
||||
}
|
||||
self.finish_cache_change();
|
||||
if let Some(database) = &mut self.database {
|
||||
match database.delete_session(session_id) {
|
||||
Ok(()) => {
|
||||
let _ = fs::remove_file(session_checkpoint_path(session_id));
|
||||
#[cfg(target_os = "macos")]
|
||||
self.background_chats.remove(&session_id);
|
||||
self.finish_cache_change();
|
||||
if self.session_menu == Some(session_id) {
|
||||
self.session_menu = None;
|
||||
}
|
||||
@@ -2723,6 +2745,24 @@ fn session_checkpoint_path(session_id: i32) -> PathBuf {
|
||||
kv_cache_path().join(format!("{session_id}.bin"))
|
||||
}
|
||||
|
||||
fn discard_session_checkpoint_files(directory: &Path, session_id: i32) -> Result<bool, String> {
|
||||
let mut removed = false;
|
||||
for extension in ["bin", "tmp", "compacting"] {
|
||||
let path = directory.join(format!("{session_id}.{extension}"));
|
||||
match fs::remove_file(&path) {
|
||||
Ok(()) => removed = true,
|
||||
Err(error) if error.kind() == std::io::ErrorKind::NotFound => {}
|
||||
Err(error) => {
|
||||
return Err(format!(
|
||||
"Could not discard session checkpoint {}: {error}",
|
||||
path.display()
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(removed)
|
||||
}
|
||||
|
||||
fn session_compaction_checkpoint_path(session_id: i32) -> PathBuf {
|
||||
kv_cache_path().join(format!("{session_id}.compacting"))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user