From c38b1d1e1ce5008bb5a4055d84bd8df950591214 Mon Sep 17 00:00:00 2001 From: extrawurst Date: Tue, 29 Aug 2023 13:40:19 +0200 Subject: [PATCH] do not fetch commit_info if batch is the same --- src/components/commitlist.rs | 34 ++++++++++++++++------ src/components/utils/logitems.rs | 48 +++++++++++++++++++------------- 2 files changed, 54 insertions(+), 28 deletions(-) diff --git a/src/components/commitlist.rs b/src/components/commitlist.rs index e8f07181..d2428c5b 100644 --- a/src/components/commitlist.rs +++ b/src/components/commitlist.rs @@ -719,17 +719,33 @@ impl CommitList { let commits = self.commits.len(); let want_min = want_min.min(commits); - let slice_end = - want_min.saturating_add(SLICE_SIZE).min(commits); - let commits = sync::get_commits_info( - &self.repo.borrow(), - &self.commits[want_min..slice_end], - self.current_size().map_or(100u16, |size| size.0).into(), - ); + if !self + .items + .index_offset_raw() + .map(|index| want_min == index) + .unwrap_or_default() + { + let slice_end = + want_min.saturating_add(SLICE_SIZE).min(commits); - if let Ok(commits) = commits { - self.items.set_items(want_min, commits, &self.highlights); + log::info!("fetch_commits: {want_min}-{slice_end}",); + + let commits = sync::get_commits_info( + &self.repo.borrow(), + &self.commits[want_min..slice_end], + self.current_size() + .map_or(100u16, |size| size.0) + .into(), + ); + + if let Ok(commits) = commits { + self.items.set_items( + want_min, + commits, + &self.highlights, + ); + } } } } diff --git a/src/components/utils/logitems.rs b/src/components/utils/logitems.rs index b6b113f6..cbf3c6ff 100644 --- a/src/components/utils/logitems.rs +++ b/src/components/utils/logitems.rs @@ -77,18 +77,23 @@ impl LogEntry { /// #[derive(Default)] pub struct ItemBatch { - index_offset: usize, + index_offset: Option, items: Vec, highlighting: bool, } impl ItemBatch { fn last_idx(&self) -> usize { - self.index_offset + self.items.len() + self.index_offset() + self.items.len() } /// - pub const fn index_offset(&self) -> usize { + pub fn index_offset(&self) -> usize { + self.index_offset.unwrap_or_default() + } + + /// + pub const fn index_offset_raw(&self) -> Option { self.index_offset } @@ -105,6 +110,7 @@ impl ItemBatch { /// clear curent list of items pub fn clear(&mut self) { self.items.clear(); + self.index_offset = None; } /// insert new batch of items @@ -114,21 +120,25 @@ impl ItemBatch { commits: Vec, highlighted: &Option>>, ) { - self.items.clear(); - self.items.extend(commits.into_iter().map(|c| { - let id = c.id; - let mut entry = LogEntry::from(c); - if highlighted - .as_ref() - .map(|highlighted| highlighted.contains(&id)) - .unwrap_or_default() - { - entry.highlighted = true; - } - entry - })); - self.highlighting = highlighted.is_some(); - self.index_offset = start_index; + self.clear(); + + if !commits.is_empty() { + self.items.extend(commits.into_iter().map(|c| { + let id = c.id; + let mut entry = LogEntry::from(c); + if highlighted + .as_ref() + .map(|highlighted| highlighted.contains(&id)) + .unwrap_or_default() + { + entry.highlighted = true; + } + entry + })); + + self.index_offset = Some(start_index); + self.highlighting = highlighted.is_some(); + } } /// returns `true` if we should fetch updated list of items @@ -139,7 +149,7 @@ impl ItemBatch { .saturating_add(SLICE_OFFSET_RELOAD_THRESHOLD) .min(idx_max); - let needs_data_top = want_min < self.index_offset; + let needs_data_top = want_min < self.index_offset(); let needs_data_bottom = want_max >= self.last_idx(); needs_data_bottom || needs_data_top }