Add database query and assertion to check for missing statuses. Only runs when running a DEBUG build.
Also: remove unused function existingStatusesForArticleIDs.
This commit is contained in:
parent
5a5d8ee01c
commit
57e63c1385
@ -29,6 +29,18 @@ final class StatusesTable: DatabaseTable {
|
|||||||
// MARK: - Creating/Updating
|
// MARK: - Creating/Updating
|
||||||
|
|
||||||
func ensureStatusesForArticleIDs(_ articleIDs: Set<String>, _ read: Bool, _ database: FMDatabase) -> ([String: ArticleStatus], Set<String>) {
|
func ensureStatusesForArticleIDs(_ articleIDs: Set<String>, _ read: Bool, _ database: FMDatabase) -> ([String: ArticleStatus], Set<String>) {
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
|
// Check for missing statuses — this asserts that all the passed-in articleIDs exist in the statuses table.
|
||||||
|
defer {
|
||||||
|
if let resultSet = self.selectRowsWhere(key: DatabaseKey.articleID, inValues: Array(articleIDs), in: database) {
|
||||||
|
let fetchedStatuses = resultSet.mapToSet(statusWithRow)
|
||||||
|
let fetchedArticleIDs = Set(fetchedStatuses.map{ $0.articleID })
|
||||||
|
assert(fetchedArticleIDs == articleIDs)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// Check cache.
|
// Check cache.
|
||||||
let articleIDsMissingCachedStatus = articleIDsWithNoCachedStatus(articleIDs)
|
let articleIDsMissingCachedStatus = articleIDsWithNoCachedStatus(articleIDs)
|
||||||
if articleIDsMissingCachedStatus.isEmpty {
|
if articleIDsMissingCachedStatus.isEmpty {
|
||||||
@ -43,23 +55,10 @@ final class StatusesTable: DatabaseTable {
|
|||||||
// Create new statuses.
|
// Create new statuses.
|
||||||
self.createAndSaveStatusesForArticleIDs(articleIDsNeedingStatus, read, database)
|
self.createAndSaveStatusesForArticleIDs(articleIDsNeedingStatus, read, database)
|
||||||
}
|
}
|
||||||
|
|
||||||
return (statusesDictionary(articleIDs), articleIDsNeedingStatus)
|
return (statusesDictionary(articleIDs), articleIDsNeedingStatus)
|
||||||
}
|
}
|
||||||
|
|
||||||
func existingStatusesForArticleIDs(_ articleIDs: Set<String>, _ database: FMDatabase) -> [String: ArticleStatus] {
|
|
||||||
// Check cache.
|
|
||||||
let articleIDsMissingCachedStatus = articleIDsWithNoCachedStatus(articleIDs)
|
|
||||||
if articleIDsMissingCachedStatus.isEmpty {
|
|
||||||
return statusesDictionary(articleIDs)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check database.
|
|
||||||
fetchAndCacheStatusesForArticleIDs(articleIDsMissingCachedStatus, database)
|
|
||||||
|
|
||||||
return statusesDictionary(articleIDs)
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: - Marking
|
// MARK: - Marking
|
||||||
|
|
||||||
@discardableResult
|
@discardableResult
|
||||||
|
Loading…
x
Reference in New Issue
Block a user