Make just one database call in fetchUnreadCounts — use fetchAllUnreadCounts and process the UnreadCountDictionary.
This commit is contained in:
parent
aa5859ff27
commit
908652df51
|
@ -295,29 +295,24 @@ final class ArticlesTable: DatabaseTable {
|
|||
return
|
||||
}
|
||||
|
||||
queue.runInDatabase { databaseResult in
|
||||
fetchAllUnreadCounts { (unreadCountsResult) in
|
||||
|
||||
func makeDatabaseCalls(_ database: FMDatabase) {
|
||||
var unreadCountDictionary = UnreadCountDictionary()
|
||||
func createUnreadCountDictionary(_ unreadCountDictionary: UnreadCountDictionary) -> UnreadCountDictionary {
|
||||
var d = UnreadCountDictionary()
|
||||
for webFeedID in webFeedIDs {
|
||||
unreadCountDictionary[webFeedID] = self.fetchUnreadCount(webFeedID, database)
|
||||
d[webFeedID] = unreadCountDictionary[webFeedID] ?? 0
|
||||
}
|
||||
return d
|
||||
}
|
||||
|
||||
DispatchQueue.main.async {
|
||||
completion(.success(unreadCountDictionary))
|
||||
}
|
||||
}
|
||||
|
||||
switch databaseResult {
|
||||
case .success(let database):
|
||||
makeDatabaseCalls(database)
|
||||
switch unreadCountsResult {
|
||||
case .success(let unreadCountDictionary):
|
||||
completion(.success(createUnreadCountDictionary(unreadCountDictionary)))
|
||||
case .failure(let databaseError):
|
||||
DispatchQueue.main.async {
|
||||
completion(.failure(databaseError))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func fetchUnreadCount(_ webFeedIDs: Set<String>, _ since: Date, _ completion: @escaping SingleUnreadCountCompletionBlock) {
|
||||
// Get unread count for today, for instance.
|
||||
|
|
Loading…
Reference in New Issue