Fix crashing bug caused by nesting update statements.

This commit is contained in:
Maurice Parker 2019-05-21 17:59:33 -05:00
parent be81fdae0a
commit d289bbea94
2 changed files with 10 additions and 8 deletions

View File

@ -187,10 +187,10 @@ final class ArticlesTable: DatabaseTable {
func ensureStatuses(_ articleIDs: Set<String>, _ statusKey: ArticleStatus.Key, _ flag: Bool) {
self.queue.update { (database) in
self.queue.updateSync { (database) in
let statusesDictionary = self.statusesTable.ensureStatusesForArticleIDs(articleIDs, false, database)
let statuses = Set(statusesDictionary.values)
_ = self.statusesTable.mark(statuses, statusKey, flag)
_ = self.statusesTable.mark(statuses, statusKey, flag, database)
}
}
@ -312,8 +312,11 @@ final class ArticlesTable: DatabaseTable {
}
func mark(_ articles: Set<Article>, _ statusKey: ArticleStatus.Key, _ flag: Bool) -> Set<ArticleStatus>? {
return statusesTable.mark(articles.statuses(), statusKey, flag)
var statuses: Set<ArticleStatus>?
self.queue.updateSync { (database) in
statuses = self.statusesTable.mark(articles.statuses(), statusKey, flag, database)
}
return statuses
}
// MARK: Indexing

View File

@ -50,7 +50,7 @@ final class StatusesTable: DatabaseTable {
// MARK: Marking
func mark(_ statuses: Set<ArticleStatus>, _ statusKey: ArticleStatus.Key, _ flag: Bool) -> Set<ArticleStatus>? {
func mark(_ statuses: Set<ArticleStatus>, _ statusKey: ArticleStatus.Key, _ flag: Bool, _ database: FMDatabase) -> Set<ArticleStatus>? {
// Sets flag in both memory and in database.
@ -70,9 +70,8 @@ final class StatusesTable: DatabaseTable {
}
let articleIDs = updatedStatuses.articleIDs()
queue.updateSync { (database) in
self.markArticleIDs(articleIDs, statusKey, flag, database)
}
return updatedStatuses
}