Radish alpha
h
rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5
Radicle Heartwood Protocol & Stack
Radicle
Git
While browsing the source code I found that there are some iterator
Merged did:key:z6MkwcUR...q1kL opened 8 months ago

optimization possible. So I figured I post this patchset for your to review and possibly apply.

2 files changed +32 -21 1e66c576 f6f3be43
modified crates/radicle-cli/src/commands/issue.rs
@@ -734,30 +734,33 @@ where
        None => None,
    };

-
    let mut all = Vec::new();
-
    let issues = cache.list()?;
-
    for result in issues {
-
        let (id, issue) = match result {
-
            Ok((id, issue)) => (id, issue),
-
            Err(e) => {
-
                // Skip issues that failed to load.
-
                log::error!(target: "cli", "Issue load error: {e}");
-
                continue;
-
            }
-
        };
+
    let mut all = cache
+
        .list()?
+
        .filter_map(|result| {
+
            let (id, issue) = match result {
+
                Ok((id, issue)) => (id, issue),
+
                Err(e) => {
+
                    // Skip issues that failed to load.
+
                    log::error!(target: "cli", "Issue load error: {e}");
+
                    return None;
+
                }
+
            };

-
        if let Some(a) = assignee {
-
            if !issue.assignees().any(|v| v == &Did::from(a)) {
-
                continue;
+
            if let Some(a) = assignee {
+
                if !issue.assignees().any(|v| v == &Did::from(a)) {
+
                    return None;
+
                }
            }
-
        }
-
        if let Some(s) = state {
-
            if s != issue.state() {
-
                continue;
+

+
            if let Some(s) = state {
+
                if s != issue.state() {
+
                    return None;
+
                }
            }
-
        }
-
        all.push((id, issue))
-
    }
+

+
            Some((id, issue))
+
        })
+
        .collect::<Vec<_>>();

    all.sort_by(|(id1, i1), (id2, i2)| {
        let by_timestamp = i2.timestamp().cmp(&i1.timestamp());
modified crates/radicle/src/cob/issue/cache.rs
@@ -371,6 +371,10 @@ impl Iterator for NoCacheIter<'_> {
    fn next(&mut self) -> Option<Self::Item> {
        self.inner.next()
    }
+

+
    fn size_hint(&self) -> (usize, Option<usize>) {
+
        self.inner.size_hint()
+
    }
}

impl<R> Issues for Cache<super::Issues<'_, R>, cache::NoCache>
@@ -449,6 +453,10 @@ impl Iterator for IssuesIter<'_> {
        let row = self.inner.next()?;
        Some(row.map_err(Error::from).and_then(IssuesIter::parse_row))
    }
+

+
    fn size_hint(&self) -> (usize, Option<usize>) {
+
        self.inner.size_hint()
+
    }
}

impl<R> Issues for Cache<R, StoreWriter>