Change order of suspending steps to prevent work from going to a suspended queue. Issue #1400

This commit is contained in:
Maurice Parker 2019-12-04 17:27:39 -07:00
parent 26f49d4b51
commit 95c1b36fe7
9 changed files with 60 additions and 30 deletions

View File

@ -405,8 +405,11 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
}
public func suspend() {
delegate.suspend()
public func suspendNetwork() {
delegate.suspendNetwork()
}
public func suspendDatabase() {
database.suspend()
save()
metadataFile.suspend()

View File

@ -50,7 +50,12 @@ protocol AccountDelegate {
static func validateCredentials(transport: Transport, credentials: Credentials, endpoint: URL?, completion: @escaping (Result<Credentials?, Error>) -> Void)
// For iOS, so we can suspend and resume properly.
func suspend() // Make sure no SQLite databases are open.
/// Suspend all network activity
func suspendNetwork()
/// Suspend the SQLLite databases
func suspendDatabase()
/// Make sure no SQLite databases are open and we are ready to issue network requests.
func resume()
}

View File

@ -164,9 +164,13 @@ public final class AccountManager: UnreadCountProvider {
return accountsDictionary[accountID]
}
public func suspendAll() {
public func suspendNetworkAll() {
isSuspended = true
accounts.forEach { $0.suspend() }
accounts.forEach { $0.suspendNetwork() }
}
public func suspendDatabaseAll() {
accounts.forEach { $0.suspendDatabase() }
}
public func resumeAll() {

View File

@ -437,13 +437,17 @@ final class FeedWranglerAccountDelegate: AccountDelegate {
// MARK: Suspend and Resume (for iOS)
/// Suspend the sync database so that it can close its SQLite file.
func suspend() {
/// Suspend all network activity
func suspendNetwork() {
caller.cancelAll()
}
/// Suspend the SQLLite databases
func suspendDatabase() {
database.suspend()
}
/// Resume the sync database let it reopen its SQLite file.
/// Make sure no SQLite databases are open and we are ready to issue network requests.
func resume() {
database.resume()
}

View File

@ -554,13 +554,17 @@ final class FeedbinAccountDelegate: AccountDelegate {
// MARK: Suspend and Resume (for iOS)
/// Suspend the sync database so that it can close its SQLite file.
func suspend() {
/// Suspend all network activity
func suspendNetwork() {
caller.suspend()
}
/// Suspend the SQLLite databases
func suspendDatabase() {
database.suspend()
}
/// Resume the sync database let it reopen its SQLite file.
/// Make sure no SQLite databases are open and we are ready to issue network requests.
func resume() {
caller.resume()
database.resume()

View File

@ -509,13 +509,17 @@ final class FeedlyAccountDelegate: AccountDelegate {
// MARK: Suspend and Resume (for iOS)
/// Suspend the sync database so that it can close its SQLite file.
func suspend() {
/// Suspend all network activity
func suspendNetwork() {
operationQueue.cancelAllOperations()
}
/// Suspend the SQLLite databases
func suspendDatabase() {
database.suspend()
}
/// Resume the sync database let it reopen its SQLite file.
/// Make sure no SQLite databases are open and we are ready to issue network requests.
func resume() {
database.resume()
}

View File

@ -31,10 +31,6 @@ final class LocalAccountDelegate: AccountDelegate {
return refresher.progress
}
func cancelAll(for account: Account) {
refresher.cancelAll()
}
func refreshAll(for account: Account, completion: @escaping (Result<Void, Error>) -> Void) {
refresher.refreshFeeds(account.flattenedWebFeeds()) {
completion(.success(()))
@ -205,10 +201,14 @@ final class LocalAccountDelegate: AccountDelegate {
// MARK: Suspend and Resume (for iOS)
func suspend() {
// Nothing to do
func suspendNetwork() {
refresher.cancelAll()
}
func suspendDatabase() {
// Nothing to do
}
func resume() {
// Nothing to do
}

View File

@ -435,13 +435,17 @@ final class ReaderAPIAccountDelegate: AccountDelegate {
// MARK: Suspend and Resume (for iOS)
/// Suspend the sync database so that it can close its SQLite file.
func suspend() {
/// Suspend all network activity
func suspendNetwork() {
caller.cancelAll()
}
/// Suspend the SQLLite databases
func suspendDatabase() {
database.suspend()
}
/// Resume the sync database let it reopen its SQLite file.
/// Make sure no SQLite databases are open and we are ready to issue network requests.
func resume() {
database.resume()
}

View File

@ -303,14 +303,16 @@ private extension AppDelegate {
func suspendApplication() {
guard !isAnySceneInForeground else { return }
AccountManager.shared.suspendNetworkAll()
CoalescingQueue.standard.performCallsImmediately()
for scene in UIApplication.shared.connectedScenes {
if let sceneDelegate = scene.delegate as? SceneDelegate {
sceneDelegate.suspend()
}
}
AccountManager.shared.saveAll()
AccountManager.shared.suspendAll()
AccountManager.shared.suspendDatabaseAll()
}
}