Make just one database call in fetchUnreadCounts — use fetchAllUnreadCounts and process the UnreadCountDictionary.
This commit is contained in:
parent
aa5859ff27
commit
908652df51
@ -295,26 +295,21 @@ final class ArticlesTable: DatabaseTable {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
queue.runInDatabase { databaseResult in
|
fetchAllUnreadCounts { (unreadCountsResult) in
|
||||||
|
|
||||||
func makeDatabaseCalls(_ database: FMDatabase) {
|
func createUnreadCountDictionary(_ unreadCountDictionary: UnreadCountDictionary) -> UnreadCountDictionary {
|
||||||
var unreadCountDictionary = UnreadCountDictionary()
|
var d = UnreadCountDictionary()
|
||||||
for webFeedID in webFeedIDs {
|
for webFeedID in webFeedIDs {
|
||||||
unreadCountDictionary[webFeedID] = self.fetchUnreadCount(webFeedID, database)
|
d[webFeedID] = unreadCountDictionary[webFeedID] ?? 0
|
||||||
}
|
|
||||||
|
|
||||||
DispatchQueue.main.async {
|
|
||||||
completion(.success(unreadCountDictionary))
|
|
||||||
}
|
}
|
||||||
|
return d
|
||||||
}
|
}
|
||||||
|
|
||||||
switch databaseResult {
|
switch unreadCountsResult {
|
||||||
case .success(let database):
|
case .success(let unreadCountDictionary):
|
||||||
makeDatabaseCalls(database)
|
completion(.success(createUnreadCountDictionary(unreadCountDictionary)))
|
||||||
case .failure(let databaseError):
|
case .failure(let databaseError):
|
||||||
DispatchQueue.main.async {
|
|
||||||
completion(.failure(databaseError))
|
completion(.failure(databaseError))
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user