DRY up the debounce of db extension version increment.
This commit is contained in:
parent
20de087441
commit
29bb69032a
|
@ -4904,11 +4904,9 @@ typedef enum : NSUInteger {
|
|||
}];
|
||||
|
||||
// Flag to ensure that we only increment once per launch.
|
||||
static BOOL hasIncrementedDatabaseView = NO;
|
||||
if (hasError && !hasIncrementedDatabaseView) {
|
||||
if (hasError) {
|
||||
OWSLogWarn(@"incrementing version of: %@", TSMessageDatabaseViewExtensionName);
|
||||
[OWSPrimaryStorage incrementVersionOfDatabaseExtension:TSMessageDatabaseViewExtensionName];
|
||||
hasIncrementedDatabaseView = YES;
|
||||
}
|
||||
|
||||
// Update the "break" properties (shouldShowDate and unreadIndicator) of the view items.
|
||||
|
|
|
@ -880,11 +880,9 @@ NSString *const kArchivedConversationsReuseIdentifier = @"kArchivedConversations
|
|||
withMappings:self.threadMappings];
|
||||
}];
|
||||
|
||||
static BOOL hasIncrementedDatabaseView = NO;
|
||||
if (![thread isKindOfClass:[TSThread class]] && !hasIncrementedDatabaseView) {
|
||||
if (![thread isKindOfClass:[TSThread class]]) {
|
||||
OWSLogError(@"Invalid object in thread view: %@", [thread class]);
|
||||
[OWSStorage incrementVersionOfDatabaseExtension:TSThreadDatabaseViewExtensionName];
|
||||
hasIncrementedDatabaseView = YES;
|
||||
}
|
||||
|
||||
return thread;
|
||||
|
|
|
@ -515,6 +515,20 @@ NSString *const kNSUserDefaults_DatabaseExtensionVersionMap = @"kNSUserDefaults_
|
|||
{
|
||||
OWSLogError(@"%@", extensionName);
|
||||
|
||||
// Don't increment version of a given extension more than once
|
||||
// per launch.
|
||||
static NSMutableSet<NSString *> *incrementedViewSet = nil;
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
incrementedViewSet = [NSMutableSet new];
|
||||
});
|
||||
@synchronized(incrementedViewSet) {
|
||||
if ([incrementedViewSet containsObject:extensionName]) {
|
||||
OWSLogInfo(@"Ignoring redundant increment: %@", extensionName);
|
||||
}
|
||||
[incrementedViewSet addObject:extensionName];
|
||||
}
|
||||
|
||||
NSUserDefaults *appUserDefaults = [NSUserDefaults appUserDefaults];
|
||||
OWSAssertDebug(appUserDefaults);
|
||||
NSMutableDictionary<NSString *, NSNumber *> *_Nullable versionMap =
|
||||
|
|
Loading…
Reference in New Issue