Resume databases for all accounts before resuming anything else, so that notifications don’t trigger database calls.

This commit is contained in:
Brent Simmons 2019-12-04 22:11:20 -08:00
parent 3c8c346ce7
commit a5c1341b0c
2 changed files with 9 additions and 1 deletions

View File

@ -417,9 +417,15 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
opmlFile.suspend()
}
public func resume() {
/// Re-open the SQLite database and allow database calls.
/// Call this *before* calling resume.
public func resumeDatabaseAndDelegate() {
database.resume()
delegate.resume()
}
/// Reload OPML, etc.
public func resume() {
metadataFile.resume()
webFeedMetadataFile.resume()
opmlFile.resume()
@ -481,6 +487,7 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
for feed in flattenedWebFeeds() {
feed.metadata = webFeedMetadata(feedURL: feed.url, webFeedID: feed.webFeedID)
}
precondition(!database.isSuspended)
fetchAllUnreadCounts()
NotificationCenter.default.post(name: .WebFeedMetadataDidChange, object: self, userInfo: nil)
}

View File

@ -175,6 +175,7 @@ public final class AccountManager: UnreadCountProvider {
public func resumeAll() {
isSuspended = false
accounts.forEach { $0.resumeDatabaseAndDelegate() }
accounts.forEach { $0.resume() }
}