Assert that GRDB schema/data migrations are complete before we warm caches.

This commit is contained in:
Matthew Chen 2021-09-20 15:17:28 -03:00
parent 004717ff35
commit b058317777
15 changed files with 42 additions and 0 deletions

View File

@ -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)
}

View File

@ -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))
}

View File

@ -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 }

View File

@ -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]()

View File

@ -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)

View File

@ -248,6 +248,8 @@ NSString *NSStringForOWSRegistrationState(OWSRegistrationState value)
- (void)warmCaches
{
OWSAssertDebug(GRDBSchemaMigrator.areMigrationsComplete);
TSAccountState *accountState = [self loadAccountStateWithSneakyTransaction];
[accountState log];

View File

@ -423,6 +423,8 @@ public class SignalServiceAddressCache: NSObject {
@objc
func warmCaches() {
owsAssertDebug(GRDBSchemaMigrator.areMigrationsComplete)
let localNumber = TSAccountManager.shared.localNumber
let localUuid = TSAccountManager.shared.localUuid

View File

@ -229,6 +229,8 @@ public class BlockingManager: NSObject {
@objc
public func warmCaches() {
owsAssertDebug(GRDBSchemaMigrator.areMigrationsComplete)
loadStateOnLaunch()
}

View File

@ -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.")

View File

@ -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
}

View File

@ -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,

View File

@ -650,6 +650,8 @@ public class KeyBackupService: NSObject {
@objc
public static func warmCaches() {
owsAssertDebug(GRDBSchemaMigrator.areMigrationsComplete)
let state = getOrLoadStateWithSneakyTransaction()
migrateEnclavesIfNecessary(state: state)
}

View File

@ -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,

View File

@ -509,6 +509,8 @@ public class ServiceRemoteConfigManager: NSObject, RemoteConfigManager {
}
public func warmCaches() {
owsAssertDebug(GRDBSchemaMigrator.areMigrationsComplete)
cacheCurrent()
AppReadiness.runNowOrWhenAppWillBecomeReady {

View File

@ -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,