From aa30e943fada728b54887cbfc4cbdc0a7b786bf7 Mon Sep 17 00:00:00 2001 From: Erik Kundt Date: Wed, 17 Dec 2025 11:06:24 +0100 Subject: [PATCH] bin/inbox: Refactor notification loading --- bin/commands/inbox/list.rs | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/bin/commands/inbox/list.rs b/bin/commands/inbox/list.rs index 57fd63d9..2408296c 100644 --- a/bin/commands/inbox/list.rs +++ b/bin/commands/inbox/list.rs @@ -705,16 +705,14 @@ impl Task for NotificationLoader { fn run(&self) -> anyhow::Result> { let profile = self.context.profile.clone(); + let notifs = profile.notifications_mut()?; let notifications = match self.context.mode { RepositoryMode::All => { - let notifs = profile.notifications_mut()?; - // Store all repos the notifs arised from, such that // they can be referenced when loading issues and patches - let all = notifs.all()?; - let repos = all - .into_iter() + let repos = notifs + .all()? .filter_map(|notif| notif.ok()) .filter_map(|notif| { profile @@ -726,9 +724,10 @@ impl Task for NotificationLoader { .collect::>(); // Only retrieve issues and patches once per repository - let all = notifs.all()?; let (mut issues, mut patches) = (HashMap::new(), HashMap::new()); - all.filter_map(|notif| notif.ok()) + notifs + .all()? + .filter_map(|notif| notif.ok()) .map(|notif| match repos.get(¬if.repo) { Some(repo) => { let project = repo.project()?; @@ -745,7 +744,7 @@ impl Task for NotificationLoader { ) }; - match NotificationKind::new(&repo, issues, patches, ¬if)? { + match NotificationKind::new(repo, issues, patches, ¬if)? { Some(kind) => Notification::new(&profile, &project, ¬if, kind), _ => Ok(None), } @@ -761,18 +760,16 @@ impl Task for NotificationLoader { let project = repo.project()?; let issues = profile.issues(&repo)?; let patches = profile.patches(&repo)?; - let notifs = profile.notifications_mut()?; let by_repo = notifs.by_repo(&repo.id, "timestamp")?; by_repo .filter_map(|notif| notif.ok()) - .map(|notif| { - let repo = self.context.profile.storage.repository(notif.repo)?; - match NotificationKind::new(&repo, &issues, &patches, ¬if)? { + .map( + |notif| match NotificationKind::new(&repo, &issues, &patches, ¬if)? { Some(kind) => Notification::new(&profile, &project, ¬if, kind), _ => Ok(None), - } - }) + }, + ) .filter_map(|notif| notif.ok()) .flatten() .collect::>() @@ -782,18 +779,16 @@ impl Task for NotificationLoader { let project = repo.project()?; let issues = profile.issues(&repo)?; let patches = profile.patches(&repo)?; - let notifs = profile.notifications_mut()?; let by_repo = notifs.by_repo(&repo.id, "timestamp")?; by_repo .filter_map(|notif| notif.ok()) - .map(|notif| { - let repo = self.context.profile.storage.repository(notif.repo)?; - match NotificationKind::new(&repo, &issues, &patches, ¬if)? { + .map( + |notif| match NotificationKind::new(&repo, &issues, &patches, ¬if)? { Some(kind) => Notification::new(&profile, &project, ¬if, kind), _ => Ok(None), - } - }) + }, + ) .filter_map(|notif| notif.ok()) .flatten() .collect::>()