From 58285019369112e6fc90fe6decdbbdb1a4a34e1d Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Thu, 4 Jun 2026 08:11:06 -0700 Subject: [PATCH] Use URL for a secondary sort to make it stable. --- Mac/AccountStats/AccountStatsViewModel.swift | 26 +++++++------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/Mac/AccountStats/AccountStatsViewModel.swift b/Mac/AccountStats/AccountStatsViewModel.swift index 9b21f5a9b..0b5517708 100644 --- a/Mac/AccountStats/AccountStatsViewModel.swift +++ b/Mac/AccountStats/AccountStatsViewModel.swift @@ -8,6 +8,7 @@ import Foundation import Account import ArticlesDatabase +import RSCore struct AccountStatsRowData { @@ -78,21 +79,21 @@ struct AccountStatsTotals { let ascending = sortDescriptor?.ascending ?? true switch sortDescriptor?.key ?? "name" { case "name": - sortedAccountStats.sort { Self.compareStrings($0.name, $1.name, ascending: ascending) } + sortedAccountStats.sort { compareStrings($0.name, $1.name, ascending: ascending) } case "databaseSizeBytes": - sortedAccountStats.sort { Self.compareInts($0.databaseSizeBytes, $1.databaseSizeBytes, ascending: ascending) } + sortedAccountStats.sort { compareValues($0.databaseSizeBytes, $1.databaseSizeBytes, ascending: ascending) } case "feedCount": - sortedAccountStats.sort { Self.compareInts($0.feedCount, $1.feedCount, ascending: ascending) } + sortedAccountStats.sort { compareValues($0.feedCount, $1.feedCount, ascending: ascending) } case "folderCount": - sortedAccountStats.sort { Self.compareInts($0.folderCount, $1.folderCount, ascending: ascending) } + sortedAccountStats.sort { compareValues($0.folderCount, $1.folderCount, ascending: ascending) } case "articleCount": - sortedAccountStats.sort { Self.compareInts($0.articleCount, $1.articleCount, ascending: ascending) } + sortedAccountStats.sort { compareValues($0.articleCount, $1.articleCount, ascending: ascending) } case "statusesCount": - sortedAccountStats.sort { Self.compareInts($0.statusesCount, $1.statusesCount, ascending: ascending) } + sortedAccountStats.sort { compareValues($0.statusesCount, $1.statusesCount, ascending: ascending) } case "unreadCount": - sortedAccountStats.sort { Self.compareInts($0.unreadCount, $1.unreadCount, ascending: ascending) } + sortedAccountStats.sort { compareValues($0.unreadCount, $1.unreadCount, ascending: ascending) } case "starredCount": - sortedAccountStats.sort { Self.compareInts($0.starredCount, $1.starredCount, ascending: ascending) } + sortedAccountStats.sort { compareValues($0.starredCount, $1.starredCount, ascending: ascending) } default: break } @@ -101,15 +102,6 @@ struct AccountStatsTotals { private extension AccountStatsViewModel { - static func compareStrings(_ lhs: String, _ rhs: String, ascending: Bool) -> Bool { - let result = lhs.localizedCaseInsensitiveCompare(rhs) - return ascending ? result == .orderedAscending : result == .orderedDescending - } - - static func compareInts(_ lhs: Int, _ rhs: Int, ascending: Bool) -> Bool { - ascending ? lhs < rhs : lhs > rhs - } - func databaseSize(for account: Account) -> Int { let dataFolder = account.dataFolder as NSString let databaseNames = ["DB.sqlite3", "FeedSettings.db", "Sync.sqlite3"]