Skip to content

Commit c38b1d1

Browse files
committed
do not fetch commit_info if batch is the same
1 parent f639f4a commit c38b1d1

File tree

2 files changed

+54
-28
lines changed

2 files changed

+54
-28
lines changed

src/components/commitlist.rs

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -719,17 +719,33 @@ impl CommitList {
719719
let commits = self.commits.len();
720720

721721
let want_min = want_min.min(commits);
722-
let slice_end =
723-
want_min.saturating_add(SLICE_SIZE).min(commits);
724722

725-
let commits = sync::get_commits_info(
726-
&self.repo.borrow(),
727-
&self.commits[want_min..slice_end],
728-
self.current_size().map_or(100u16, |size| size.0).into(),
729-
);
723+
if !self
724+
.items
725+
.index_offset_raw()
726+
.map(|index| want_min == index)
727+
.unwrap_or_default()
728+
{
729+
let slice_end =
730+
want_min.saturating_add(SLICE_SIZE).min(commits);
731+
732+
log::info!("fetch_commits: {want_min}-{slice_end}",);
730733

731-
if let Ok(commits) = commits {
732-
self.items.set_items(want_min, commits, &self.highlights);
734+
let commits = sync::get_commits_info(
735+
&self.repo.borrow(),
736+
&self.commits[want_min..slice_end],
737+
self.current_size()
738+
.map_or(100u16, |size| size.0)
739+
.into(),
740+
);
741+
742+
if let Ok(commits) = commits {
743+
self.items.set_items(
744+
want_min,
745+
commits,
746+
&self.highlights,
747+
);
748+
}
733749
}
734750
}
735751
}

src/components/utils/logitems.rs

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -77,18 +77,23 @@ impl LogEntry {
7777
///
7878
#[derive(Default)]
7979
pub struct ItemBatch {
80-
index_offset: usize,
80+
index_offset: Option<usize>,
8181
items: Vec<LogEntry>,
8282
highlighting: bool,
8383
}
8484

8585
impl ItemBatch {
8686
fn last_idx(&self) -> usize {
87-
self.index_offset + self.items.len()
87+
self.index_offset() + self.items.len()
8888
}
8989

9090
///
91-
pub const fn index_offset(&self) -> usize {
91+
pub fn index_offset(&self) -> usize {
92+
self.index_offset.unwrap_or_default()
93+
}
94+
95+
///
96+
pub const fn index_offset_raw(&self) -> Option<usize> {
9297
self.index_offset
9398
}
9499

@@ -105,6 +110,7 @@ impl ItemBatch {
105110
/// clear curent list of items
106111
pub fn clear(&mut self) {
107112
self.items.clear();
113+
self.index_offset = None;
108114
}
109115

110116
/// insert new batch of items
@@ -114,21 +120,25 @@ impl ItemBatch {
114120
commits: Vec<CommitInfo>,
115121
highlighted: &Option<Rc<IndexSet<CommitId>>>,
116122
) {
117-
self.items.clear();
118-
self.items.extend(commits.into_iter().map(|c| {
119-
let id = c.id;
120-
let mut entry = LogEntry::from(c);
121-
if highlighted
122-
.as_ref()
123-
.map(|highlighted| highlighted.contains(&id))
124-
.unwrap_or_default()
125-
{
126-
entry.highlighted = true;
127-
}
128-
entry
129-
}));
130-
self.highlighting = highlighted.is_some();
131-
self.index_offset = start_index;
123+
self.clear();
124+
125+
if !commits.is_empty() {
126+
self.items.extend(commits.into_iter().map(|c| {
127+
let id = c.id;
128+
let mut entry = LogEntry::from(c);
129+
if highlighted
130+
.as_ref()
131+
.map(|highlighted| highlighted.contains(&id))
132+
.unwrap_or_default()
133+
{
134+
entry.highlighted = true;
135+
}
136+
entry
137+
}));
138+
139+
self.index_offset = Some(start_index);
140+
self.highlighting = highlighted.is_some();
141+
}
132142
}
133143

134144
/// returns `true` if we should fetch updated list of items
@@ -139,7 +149,7 @@ impl ItemBatch {
139149
.saturating_add(SLICE_OFFSET_RELOAD_THRESHOLD)
140150
.min(idx_max);
141151

142-
let needs_data_top = want_min < self.index_offset;
152+
let needs_data_top = want_min < self.index_offset();
143153
let needs_data_bottom = want_max >= self.last_idx();
144154
needs_data_bottom || needs_data_top
145155
}

0 commit comments

Comments
 (0)