cli/issue: Optimize how the issues are collected

This patch optimizes how the issues are collected.
Before, the issues where pushed to a new instance of `Vec`, which was
not preallocated to the size of the iterator.
This could be slow when a large number of issues is returned by the
iterator.

With the `Iterator::collect` function, the `FromIterator` implementation
of `Vec` is used, which makes use of `Iterator::size_hint` for
optimizing how much space is preallocated when collecting into the
`Vec`.

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
This commit is contained in:
Matthias Beyer 2025-08-16 20:19:46 +02:00 committed by Lorenz Leutgeb
parent b49ff9e5af
commit f6f3be437b
1 changed files with 24 additions and 21 deletions

View File

@ -734,30 +734,33 @@ where
None => None, None => None,
}; };
let mut all = Vec::new(); let mut all = cache
let issues = cache.list()?; .list()?
for result in issues { .filter_map(|result| {
let (id, issue) = match result { let (id, issue) = match result {
Ok((id, issue)) => (id, issue), Ok((id, issue)) => (id, issue),
Err(e) => { Err(e) => {
// Skip issues that failed to load. // Skip issues that failed to load.
log::error!(target: "cli", "Issue load error: {e}"); log::error!(target: "cli", "Issue load error: {e}");
continue; return None;
} }
}; };
if let Some(a) = assignee { if let Some(a) = assignee {
if !issue.assignees().any(|v| v == &Did::from(a)) { if !issue.assignees().any(|v| v == &Did::from(a)) {
continue; return None;
}
} }
}
if let Some(s) = state { if let Some(s) = state {
if s != issue.state() { if s != issue.state() {
continue; return None;
}
} }
}
all.push((id, issue)) Some((id, issue))
} })
.collect::<Vec<_>>();
all.sort_by(|(id1, i1), (id2, i2)| { all.sort_by(|(id1, i1), (id2, i2)| {
let by_timestamp = i2.timestamp().cmp(&i1.timestamp()); let by_timestamp = i2.timestamp().cmp(&i1.timestamp());