mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2026-12-01 09:50:16 +00:00
Simplify fetchUnreadCounts.
This commit is contained in:
1 parent
e412f333d6
commit
291bc4613f
1 file changed
+19
-27
@@ -370,40 +370,32 @@ final class ArticlesTable: DatabaseTable, Sendable {
|
||||
}
|
||||
|
||||
queue.runInDatabase { database in
|
||||
let placeholders = NSString.rs_SQLValueList(withPlaceholders: UInt(feedIDs.count))!
|
||||
let sql = "select distinct feedID, count(*) from articles natural join statuses where feedID in \(placeholders) and read=0 group by feedID;"
|
||||
|
||||
func makeDatabaseCalls(_ database: FMDatabase) throws -> UnreadCountDictionary {
|
||||
let placeholders = NSString.rs_SQLValueList(withPlaceholders: UInt(feedIDs.count))!
|
||||
let sql = "select distinct feedID, count(*) from articles natural join statuses where feedID in \(placeholders) and read=0 group by feedID;"
|
||||
let parameters = Array(feedIDs) as [Any]
|
||||
|
||||
let parameters = Array(feedIDs) as [Any]
|
||||
|
||||
guard let resultSet = database.executeQuery(sql, withArgumentsIn: parameters) else {
|
||||
return UnreadCountDictionary()
|
||||
guard let resultSet = database.executeQuery(sql, withArgumentsIn: parameters) else {
|
||||
DispatchQueue.main.async {
|
||||
completion(.success(UnreadCountDictionary()))
|
||||
}
|
||||
defer {
|
||||
resultSet.close()
|
||||
}
|
||||
|
||||
var unreadCountDictionary = UnreadCountDictionary()
|
||||
while resultSet.next() {
|
||||
let unreadCount = resultSet.long(forColumnIndex: 1)
|
||||
if let feedID = resultSet.swiftString(forColumnIndex: 0) {
|
||||
unreadCountDictionary[feedID] = unreadCount
|
||||
}
|
||||
}
|
||||
return unreadCountDictionary
|
||||
return
|
||||
}
|
||||
defer {
|
||||
resultSet.close()
|
||||
}
|
||||
|
||||
do {
|
||||
let unreadCountDictionary = try makeDatabaseCalls(database)
|
||||
DispatchQueue.main.async {
|
||||
completion(.success(unreadCountDictionary))
|
||||
}
|
||||
} catch {
|
||||
DispatchQueue.main.async {
|
||||
completion(.failure(error))
|
||||
var unreadCountDictionary = UnreadCountDictionary()
|
||||
while resultSet.next() {
|
||||
let unreadCount = resultSet.long(forColumnIndex: 1)
|
||||
if let feedID = resultSet.swiftString(forColumnIndex: 0) {
|
||||
unreadCountDictionary[feedID] = unreadCount
|
||||
}
|
||||
}
|
||||
|
||||
DispatchQueue.main.async {
|
||||
completion(.success(unreadCountDictionary))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user