mirror of
https://github.com/gitui-org/gitui
synced 2026-05-23 08:58:21 +00:00
do not fetch commit_info if batch is the same
This commit is contained in:
parent
f639f4a0d0
commit
c38b1d1e1c
2 changed files with 54 additions and 28 deletions
|
|
@ -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,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -77,18 +77,23 @@ impl LogEntry {
|
|||
///
|
||||
#[derive(Default)]
|
||||
pub struct ItemBatch {
|
||||
index_offset: usize,
|
||||
index_offset: Option<usize>,
|
||||
items: Vec<LogEntry>,
|
||||
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<usize> {
|
||||
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<CommitInfo>,
|
||||
highlighted: &Option<Rc<IndexSet<CommitId>>>,
|
||||
) {
|
||||
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
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue