mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
Flush multi-process writes more aggressively.
This commit is contained in:
parent
f9bbbbd0c9
commit
e7b9f7da99
|
@ -1237,6 +1237,8 @@ static NSTimeInterval launchStartedAt;
|
||||||
|
|
||||||
[self preheatDatabaseViews];
|
[self preheatDatabaseViews];
|
||||||
|
|
||||||
|
[self.primaryStorage touchDbAsync];
|
||||||
|
|
||||||
// Try to update account attributes every time we upgrade.
|
// Try to update account attributes every time we upgrade.
|
||||||
if ([self.tsAccountManager isRegistered]) {
|
if ([self.tsAccountManager isRegistered]) {
|
||||||
AppVersion *appVersion = AppVersion.sharedInstance;
|
AppVersion *appVersion = AppVersion.sharedInstance;
|
||||||
|
|
|
@ -337,6 +337,42 @@ static const int kYapDatabaseRangeMaxLength = 25000;
|
||||||
- (void)viewDidLoad
|
- (void)viewDidLoad
|
||||||
{
|
{
|
||||||
[self addNotificationListeners];
|
[self addNotificationListeners];
|
||||||
|
|
||||||
|
[self touchDbAsync];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)touchDbAsync
|
||||||
|
{
|
||||||
|
// See comments in primaryStorage.touchDbAsync.
|
||||||
|
[self.primaryStorage touchDbAsync];
|
||||||
|
|
||||||
|
id<ConversationViewItem> _Nullable firstViewItem = self.viewItems.firstObject;
|
||||||
|
if (firstViewItem) {
|
||||||
|
__weak ConversationViewModel *weakSelf = self;
|
||||||
|
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.15 * NSEC_PER_SEC)),
|
||||||
|
dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),
|
||||||
|
^{
|
||||||
|
ConversationViewModel *_Nullable strongSelf = weakSelf;
|
||||||
|
if (!strongSelf) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (CurrentAppContext().reportedApplicationState == UIApplicationStateBackground) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
[strongSelf.editingDatabaseConnection
|
||||||
|
readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||||
|
// Reload the interaction to ensure it still exists.
|
||||||
|
TSInteraction *_Nullable interaction =
|
||||||
|
[TSInteraction fetchObjectWithUniqueID:firstViewItem.interaction.uniqueId
|
||||||
|
transaction:transaction];
|
||||||
|
if (!interaction) {
|
||||||
|
// Interaction appears to have been deleted.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
[interaction touchWithTransaction:transaction];
|
||||||
|
}];
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)dealloc
|
- (void)dealloc
|
||||||
|
@ -963,22 +999,8 @@ static const int kYapDatabaseRangeMaxLength = 25000;
|
||||||
[self.delegate conversationViewModelDidUpdate:ConversationUpdate.reloadUpdate];
|
[self.delegate conversationViewModelDidUpdate:ConversationUpdate.reloadUpdate];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)touchDbAsync
|
|
||||||
{
|
|
||||||
OWSLogInfo(@"");
|
|
||||||
|
|
||||||
// There appears to be a bug in YapDatabase that sometimes delays modifications
|
|
||||||
// made in another process (e.g. the SAE) from showing up in other processes.
|
|
||||||
// There's a simple workaround: a trivial write to the database flushes changes
|
|
||||||
// made from other processes.
|
|
||||||
[self.editingDatabaseConnection asyncReadWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
|
||||||
[transaction setObject:[NSUUID UUID].UUIDString forKey:@"conversation_view_noop_mod" inCollection:@"temp"];
|
|
||||||
}];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)applicationWillEnterForeground:(NSNotification *)notification
|
- (void)applicationWillEnterForeground:(NSNotification *)notification
|
||||||
{
|
{
|
||||||
// See comments in touchDbAsync.
|
|
||||||
[self touchDbAsync];
|
[self touchDbAsync];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
//
|
//
|
||||||
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
// Copyright (c) 2019 Open Whisper Systems. All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
#import "OWSStorage.h"
|
#import "OWSStorage.h"
|
||||||
|
@ -42,6 +42,10 @@ extern NSString *const OWSUIDatabaseConnectionNotificationsKey;
|
||||||
|
|
||||||
+ (void)protectFiles;
|
+ (void)protectFiles;
|
||||||
|
|
||||||
|
#pragma mark - Misc.
|
||||||
|
|
||||||
|
- (void)touchDbAsync;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_END
|
NS_ASSUME_NONNULL_END
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
//
|
//
|
||||||
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
// Copyright (c) 2019 Open Whisper Systems. All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
#import "OWSPrimaryStorage.h"
|
#import "OWSPrimaryStorage.h"
|
||||||
|
@ -431,6 +431,21 @@ void VerifyRegistrationsForPrimaryStorage(OWSStorage *storage)
|
||||||
return OWSPrimaryStorage.sharedManager.dbReadWriteConnection;
|
return OWSPrimaryStorage.sharedManager.dbReadWriteConnection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#pragma mark - Misc.
|
||||||
|
|
||||||
|
- (void)touchDbAsync
|
||||||
|
{
|
||||||
|
OWSLogInfo(@"");
|
||||||
|
|
||||||
|
// There appears to be a bug in YapDatabase that sometimes delays modifications
|
||||||
|
// made in another process (e.g. the SAE) from showing up in other processes.
|
||||||
|
// There's a simple workaround: a trivial write to the database flushes changes
|
||||||
|
// made from other processes.
|
||||||
|
[self.dbReadWriteConnection asyncReadWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||||
|
[transaction setObject:[NSUUID UUID].UUIDString forKey:@"conversation_view_noop_mod" inCollection:@"temp"];
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_END
|
NS_ASSUME_NONNULL_END
|
||||||
|
|
Loading…
Reference in a new issue