Skip to content

Commit

Permalink
perf(interactive): use update methods for refreshing snapshots (#1285)
Browse files Browse the repository at this point in the history
This increases speed of refreshing a lot.
  • Loading branch information
aawsome authored Oct 2, 2024
1 parent 2b8ee0f commit 68cbca3
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/commands/tui/snapshots.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{iter::once, str::FromStr};
use std::{collections::BTreeSet, iter::once, mem, str::FromStr};

use anyhow::Result;
use chrono::Local;
Expand Down Expand Up @@ -697,13 +697,17 @@ impl<'a, P: ProgressBars, S: IndexedFull> Snapshots<'a, P, S> {
let delete_ids: Vec<_> = old_snap_ids.chain(snap_ids_to_forget).collect();
self.repo.save_snapshots(save_snaps)?;
self.repo.delete_snapshots(&delete_ids)?;
// remove snapshots-to-reread
let ids: BTreeSet<_> = delete_ids.into_iter().collect();
self.snapshots.retain(|snap| !ids.contains(&snap.id));
// re-read snapshots
self.reread()
}

// re-read all snapshots
pub fn reread(&mut self) -> Result<()> {
self.snapshots = self.repo.get_all_snapshots()?;
let snapshots = mem::take(&mut self.snapshots);
self.snapshots = self.repo.update_all_snapshots(snapshots)?;
self.snapshots
.sort_unstable_by(|sn1, sn2| sn1.cmp_group(self.group_by, sn2).then(sn1.cmp(sn2)));
self.snaps_status = vec![SnapStatus::default(); self.snapshots.len()];
Expand Down

0 comments on commit 68cbca3

Please sign in to comment.