From 02cc7c2ffb504b8c9dbc729f87a766ec133b560e Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Sat, 25 Jul 2026 10:50:49 -0700 Subject: [PATCH] Coalesce Folder unread-count recalculation using CoalescingQueue. Run pending unread count updates before going to next unread. Fixes #5373. --- Mac/MainWindow/MainWindowController.swift | 3 +++ Modules/Account/Sources/Account/Folder.swift | 18 +++++++++--------- iOS/SceneCoordinator.swift | 3 +++ 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/Mac/MainWindow/MainWindowController.swift b/Mac/MainWindow/MainWindowController.swift index 774753a03..08288658d 100644 --- a/Mac/MainWindow/MainWindowController.swift +++ b/Mac/MainWindow/MainWindowController.swift @@ -387,6 +387,9 @@ final class MainWindowController: NSWindowController, NSUserInterfaceValidations return } + // Flush coalesced unread-count updates so folder counts are current. + CoalescingQueue.standard.performCallsImmediately() + NSCursor.setHiddenUntilMouseMoves(true) // TODO: handle search mode diff --git a/Modules/Account/Sources/Account/Folder.swift b/Modules/Account/Sources/Account/Folder.swift index 79bd942f9..247af6f17 100644 --- a/Modules/Account/Sources/Account/Folder.swift +++ b/Modules/Account/Sources/Account/Folder.swift @@ -92,7 +92,7 @@ public final class Folder: SidebarItem, Renamable, Container, Hashable { @objc func unreadCountDidChange(_ note: Notification) { if let object = note.object { if objectIsChild(object as AnyObject) { - updateUnreadCount() + CoalescingQueue.standard.add(self, #selector(updateUnreadCount)) } } } @@ -101,6 +101,14 @@ public final class Folder: SidebarItem, Renamable, Container, Hashable { updateUnreadCount() } + @objc func updateUnreadCount() { + var updatedUnreadCount = 0 + for feed in topLevelFeeds { + updatedUnreadCount += feed.unreadCount + } + unreadCount = updatedUnreadCount + } + // MARK: Container public func flattenedFeeds() -> Set { @@ -165,14 +173,6 @@ public final class Folder: SidebarItem, Renamable, Container, Hashable { private extension Folder { - func updateUnreadCount() { - var updatedUnreadCount = 0 - for feed in topLevelFeeds { - updatedUnreadCount += feed.unreadCount - } - unreadCount = updatedUnreadCount - } - func childrenContain(_ feed: Feed) -> Bool { return topLevelFeeds.contains(feed) } diff --git a/iOS/SceneCoordinator.swift b/iOS/SceneCoordinator.swift index 61a3c3121..fa1ed06b7 100644 --- a/iOS/SceneCoordinator.swift +++ b/iOS/SceneCoordinator.swift @@ -1157,6 +1157,9 @@ struct SidebarItemNode: Hashable, Sendable { func selectNextUnread() { + // Flush coalesced unread-count updates so folder counts are current. + CoalescingQueue.standard.performCallsImmediately() + // This should never happen, but I don't want to risk throwing us // into an infinite loop searching for an unread that isn't there. if AccountManager.shared.unreadCount < 1 {