Skip to content

Commit

Permalink
do not fetch commit_info if batch is the same
Browse files Browse the repository at this point in the history
  • Loading branch information
extrawurst committed Aug 29, 2023
1 parent f639f4a commit c38b1d1
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 28 deletions.
34 changes: 25 additions & 9 deletions src/components/commitlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

log::info!("fetch_commits: {want_min}-{slice_end}",);

if let Ok(commits) = commits {
self.items.set_items(want_min, commits, &self.highlights);
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,
);
}
}
}
}
Expand Down
48 changes: 29 additions & 19 deletions src/components/utils/logitems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
}
Expand Down

0 comments on commit c38b1d1

Please sign in to comment.