diff --git a/SignalMessaging/Payments/PaymentsCurrenciesImpl.swift b/SignalMessaging/Payments/PaymentsCurrenciesImpl.swift index 3f98017fe7..897b5d5bf1 100644 --- a/SignalMessaging/Payments/PaymentsCurrenciesImpl.swift +++ b/SignalMessaging/Payments/PaymentsCurrenciesImpl.swift @@ -27,6 +27,8 @@ public class PaymentsCurrenciesImpl: NSObject, PaymentsCurrenciesSwift { } public func warmCaches() { + owsAssertDebug(GRDBSchemaMigrator.areMigrationsComplete) + Self.databaseStorage.read { transaction in self.currentCurrencyCode = Self.loadCurrentCurrencyCode(transaction: transaction) } diff --git a/SignalMessaging/Payments/PaymentsImpl.swift b/SignalMessaging/Payments/PaymentsImpl.swift index 25f95ca7cb..eeb4fa34de 100644 --- a/SignalMessaging/Payments/PaymentsImpl.swift +++ b/SignalMessaging/Payments/PaymentsImpl.swift @@ -169,6 +169,8 @@ public class PaymentsImpl: NSObject, PaymentsSwift { public static let arePaymentsEnabledDidChange = Notification.Name("arePaymentsEnabledDidChange") public func warmCaches() { + owsAssertDebug(GRDBSchemaMigrator.areMigrationsComplete) + Self.databaseStorage.read { transaction in self.paymentStateCache.set(Self.loadPaymentsState(transaction: transaction)) } diff --git a/SignalMessaging/Wallpapers/Wallpaper.swift b/SignalMessaging/Wallpapers/Wallpaper.swift index eca50054bb..530687f413 100644 --- a/SignalMessaging/Wallpapers/Wallpaper.swift +++ b/SignalMessaging/Wallpapers/Wallpaper.swift @@ -38,6 +38,7 @@ public enum Wallpaper: String, CaseIterable { public static var defaultWallpapers: [Wallpaper] { allCases.filter { $0 != .photo } } public static func warmCaches() { + owsAssertDebug(GRDBSchemaMigrator.areMigrationsComplete) owsAssertDebug(!Thread.isMainThread) guard CurrentAppContext().hasUI else { return } diff --git a/SignalMessaging/appearance/ChatColors.swift b/SignalMessaging/appearance/ChatColors.swift index 2c3308d4ab..b2898838ab 100644 --- a/SignalMessaging/appearance/ChatColors.swift +++ b/SignalMessaging/appearance/ChatColors.swift @@ -3,6 +3,7 @@ // import Foundation +import SignalCoreKit public struct ChatColor: Equatable, Codable { public let id: String @@ -59,6 +60,8 @@ public class ChatColors: NSObject, Dependencies { // The cache should contain all current values at all times. @objc private func warmCaches() { + owsAssertDebug(GRDBSchemaMigrator.areMigrationsComplete) + guard CurrentAppContext().hasUI else { return } var valueCache = [String: ChatColor]() diff --git a/SignalMessaging/profiles/OWSProfileManager.m b/SignalMessaging/profiles/OWSProfileManager.m index 00ea0d6f12..739abdae9f 100644 --- a/SignalMessaging/profiles/OWSProfileManager.m +++ b/SignalMessaging/profiles/OWSProfileManager.m @@ -197,6 +197,8 @@ const NSString *kNSNotificationKey_UserProfileWriter = @"kNSNotificationKey_User - (void)warmCaches { + OWSAssertDebug(GRDBSchemaMigrator.areMigrationsComplete); + // Clear out so we re-initialize if we ever re-run the "on launch" logic, // such as after a completed database transfer. @synchronized(self) { @@ -217,6 +219,8 @@ const NSString *kNSNotificationKey_UserProfileWriter = @"kNSNotificationKey_User - (OWSUserProfile *)localUserProfile { + OWSAssertDebug(GRDBSchemaMigrator.areMigrationsComplete); + @synchronized(self) { if (_localUserProfile) { @@ -262,6 +266,8 @@ const NSString *kNSNotificationKey_UserProfileWriter = @"kNSNotificationKey_User - (nullable OWSUserProfile *)getLocalUserProfileWithTransaction:(SDSAnyReadTransaction *)transaction { + OWSAssertDebug(GRDBSchemaMigrator.areMigrationsComplete); + @synchronized(self) { if (_localUserProfile) { OWSAssertDebug(_localUserProfile.profileKey); @@ -286,6 +292,8 @@ const NSString *kNSNotificationKey_UserProfileWriter = @"kNSNotificationKey_User - (void)localProfileWasUpdated:(OWSUserProfile *)localUserProfile { + OWSAssertDebug(GRDBSchemaMigrator.areMigrationsComplete); + @synchronized(self) { _localUserProfile = [localUserProfile shallowCopy]; } @@ -699,6 +707,8 @@ const NSString *kNSNotificationKey_UserProfileWriter = @"kNSNotificationKey_User userProfileWriter:(UserProfileWriter)userProfileWriter transaction:(SDSAnyWriteTransaction *)transaction { + OWSAssertDebug(GRDBSchemaMigrator.areMigrationsComplete); + OWSUserProfile *localUserProfile; @synchronized(self) diff --git a/SignalServiceKit/src/Account/TSAccountManager.m b/SignalServiceKit/src/Account/TSAccountManager.m index 2a3fca7236..dea65f9ded 100644 --- a/SignalServiceKit/src/Account/TSAccountManager.m +++ b/SignalServiceKit/src/Account/TSAccountManager.m @@ -248,6 +248,8 @@ NSString *NSStringForOWSRegistrationState(OWSRegistrationState value) - (void)warmCaches { + OWSAssertDebug(GRDBSchemaMigrator.areMigrationsComplete); + TSAccountState *accountState = [self loadAccountStateWithSneakyTransaction]; [accountState log]; diff --git a/SignalServiceKit/src/Contacts/SignalServiceAddress.swift b/SignalServiceKit/src/Contacts/SignalServiceAddress.swift index 1b25834cea..653ee2527c 100644 --- a/SignalServiceKit/src/Contacts/SignalServiceAddress.swift +++ b/SignalServiceKit/src/Contacts/SignalServiceAddress.swift @@ -423,6 +423,8 @@ public class SignalServiceAddressCache: NSObject { @objc func warmCaches() { + owsAssertDebug(GRDBSchemaMigrator.areMigrationsComplete) + let localNumber = TSAccountManager.shared.localNumber let localUuid = TSAccountManager.shared.localUuid diff --git a/SignalServiceKit/src/Messages/BlockingManager.swift b/SignalServiceKit/src/Messages/BlockingManager.swift index 457ba6a225..be24d7804a 100644 --- a/SignalServiceKit/src/Messages/BlockingManager.swift +++ b/SignalServiceKit/src/Messages/BlockingManager.swift @@ -229,6 +229,8 @@ public class BlockingManager: NSObject { @objc public func warmCaches() { + owsAssertDebug(GRDBSchemaMigrator.areMigrationsComplete) + loadStateOnLaunch() } diff --git a/SignalServiceKit/src/Messages/UD/OWSUDManager.swift b/SignalServiceKit/src/Messages/UD/OWSUDManager.swift index 763f351b1f..05c0a9dd50 100644 --- a/SignalServiceKit/src/Messages/UD/OWSUDManager.swift +++ b/SignalServiceKit/src/Messages/UD/OWSUDManager.swift @@ -201,6 +201,8 @@ public class OWSUDManagerImpl: NSObject, OWSUDManager { @objc public func warmCaches() { + owsAssertDebug(GRDBSchemaMigrator.areMigrationsComplete) + let parseUnidentifiedAccessMode = { (anyValue: Any) -> UnidentifiedAccessMode? in guard let nsNumber = anyValue as? NSNumber else { owsFailDebug("Invalid value.") diff --git a/SignalServiceKit/src/Storage/Database/GRDBSchemaMigrator.swift b/SignalServiceKit/src/Storage/Database/GRDBSchemaMigrator.swift index 15267fbc43..544eb8ff1f 100644 --- a/SignalServiceKit/src/Storage/Database/GRDBSchemaMigrator.swift +++ b/SignalServiceKit/src/Storage/Database/GRDBSchemaMigrator.swift @@ -8,6 +8,10 @@ import GRDB @objc public class GRDBSchemaMigrator: NSObject { + private static let _areMigrationsComplete = AtomicBool(false) + @objc + public static var areMigrationsComplete: Bool { _areMigrationsComplete.get() } + // Returns true IFF incremental migrations were performed. @objc public func runSchemaMigrations() -> Bool { @@ -26,6 +30,8 @@ public class GRDBSchemaMigrator: NSObject { SSKPreferences.markGRDBSchemaAsLatest() + Self._areMigrationsComplete.set(true) + return didPerformIncrementalMigrations } diff --git a/SignalServiceKit/src/Util/AppExpiry.swift b/SignalServiceKit/src/Util/AppExpiry.swift index b0835f9c5b..90d0096ad3 100644 --- a/SignalServiceKit/src/Util/AppExpiry.swift +++ b/SignalServiceKit/src/Util/AppExpiry.swift @@ -59,6 +59,8 @@ public class AppExpiry: NSObject { } private func warmCaches() { + owsAssertDebug(GRDBSchemaMigrator.areMigrationsComplete) + if let persistedExpirationState: ExpirationState = databaseStorage.read(block: { transaction in guard let persistedExpirationState: ExpirationState = try? self.keyValueStore.getCodableValue( forKey: Self.expirationStateKey, diff --git a/SignalServiceKit/src/Util/KeyBackupService.swift b/SignalServiceKit/src/Util/KeyBackupService.swift index 083ee5a0f7..ebd2bb7887 100644 --- a/SignalServiceKit/src/Util/KeyBackupService.swift +++ b/SignalServiceKit/src/Util/KeyBackupService.swift @@ -650,6 +650,8 @@ public class KeyBackupService: NSObject { @objc public static func warmCaches() { + owsAssertDebug(GRDBSchemaMigrator.areMigrationsComplete) + let state = getOrLoadStateWithSneakyTransaction() migrateEnclavesIfNecessary(state: state) } diff --git a/SignalServiceKit/src/Util/PinnedThreadManager.swift b/SignalServiceKit/src/Util/PinnedThreadManager.swift index 181fd1df0d..905f1ddcad 100644 --- a/SignalServiceKit/src/Util/PinnedThreadManager.swift +++ b/SignalServiceKit/src/Util/PinnedThreadManager.swift @@ -22,6 +22,8 @@ public class PinnedThreadManager: NSObject { @objc public class func warmCaches() { + owsAssertDebug(GRDBSchemaMigrator.areMigrationsComplete) + let pinnedThreadIds = SDSDatabaseStorage.shared.read { transaction in return keyValueStore.getObject( forKey: pinnedThreadIdsKey, diff --git a/SignalServiceKit/src/Util/RemoteConfigManager.swift b/SignalServiceKit/src/Util/RemoteConfigManager.swift index 87585bfb8b..a9ecaa2bc8 100644 --- a/SignalServiceKit/src/Util/RemoteConfigManager.swift +++ b/SignalServiceKit/src/Util/RemoteConfigManager.swift @@ -509,6 +509,8 @@ public class ServiceRemoteConfigManager: NSObject, RemoteConfigManager { } public func warmCaches() { + owsAssertDebug(GRDBSchemaMigrator.areMigrationsComplete) + cacheCurrent() AppReadiness.runNowOrWhenAppWillBecomeReady { diff --git a/SignalServiceKit/src/Util/TypingIndicators.swift b/SignalServiceKit/src/Util/TypingIndicators.swift index ea41c07bd3..7a326ff5dc 100644 --- a/SignalServiceKit/src/Util/TypingIndicators.swift +++ b/SignalServiceKit/src/Util/TypingIndicators.swift @@ -66,6 +66,8 @@ public class TypingIndicatorsImpl: NSObject, TypingIndicators { @objc public func warmCaches() { + owsAssertDebug(GRDBSchemaMigrator.areMigrationsComplete) + let enabled = databaseStorage.read { transaction in self.keyValueStore.getBool( self.kDatabaseKey_TypingIndicatorsEnabled,