diff --git a/Signal/src/util/OWSBackupImportJob.m b/Signal/src/util/OWSBackupImportJob.m index 37ccab8f1..7941b8790 100644 --- a/Signal/src/util/OWSBackupImportJob.m +++ b/Signal/src/util/OWSBackupImportJob.m @@ -129,12 +129,6 @@ NSString *const kOWSBackup_ImportDatabaseKeySpec = @"kOWSBackup_ImportDatabaseKe return; } - [weakSelf restoreAttachmentFiles]; - - if (weakSelf.isComplete) { - return; - } - [weakSelf restoreDatabaseWithCompletion:^(BOOL restoreDatabaseSuccess) { if (!restoreDatabaseSuccess) { [weakSelf @@ -161,6 +155,15 @@ NSString *const kOWSBackup_ImportDatabaseKeySpec = @"kOWSBackup_ImportDatabaseKe return; } + [weakSelf restoreAttachmentFiles]; + + if (weakSelf.isComplete) { + return; + } + + // Kick off lazy restore. + [OWSBackupLazyRestoreJob run]; + [weakSelf succeed]; }]; }]; diff --git a/Signal/src/util/OWSBackupLazyRestoreJob.swift b/Signal/src/util/OWSBackupLazyRestoreJob.swift index 7c28f03da..e88c773c0 100644 --- a/Signal/src/util/OWSBackupLazyRestoreJob.swift +++ b/Signal/src/util/OWSBackupLazyRestoreJob.swift @@ -9,8 +9,6 @@ import SignalServiceKit @objc public class OWSBackupLazyRestoreJob: NSObject { - let TAG = "[OWSBackupLazyRestoreJob]" - let primaryStorage: OWSPrimaryStorage private var jobTempDirPath: String? @@ -43,10 +41,9 @@ public class OWSBackupLazyRestoreJob: NSObject { private func restoreAttachments() { let temporaryDirectory = NSTemporaryDirectory() let jobTempDirPath = (temporaryDirectory as NSString).appendingPathComponent(NSUUID().uuidString) - // let jobTempDirPath = temporaryDirectory.appendingPathComponent(UUID().uuidString) guard OWSFileSystem.ensureDirectoryExists(jobTempDirPath) else { - Logger.error("\(TAG) could not create temp directory.") + Logger.error("\(logTag) could not create temp directory.") return } @@ -55,6 +52,11 @@ public class OWSBackupLazyRestoreJob: NSObject { let backupIO = OWSBackupIO(jobTempDirPath: jobTempDirPath) let attachmentIds = OWSBackup.shared().attachmentIdsForLazyRestore() + guard attachmentIds.count > 0 else { + Logger.info("\(logTag) No attachments need lazy restore.") + return + } + Logger.info("\(logTag) Lazy restoring \(attachmentIds.count) attachments.") self.tryToRestoreNextAttachment(attachmentIds: attachmentIds, backupIO: backupIO) } @@ -62,12 +64,12 @@ public class OWSBackupLazyRestoreJob: NSObject { var attachmentIdsCopy = attachmentIds guard let attachmentId = attachmentIdsCopy.last else { // This job is done. - Logger.verbose("\(TAG) job is done.") + Logger.verbose("\(logTag) job is done.") return } attachmentIdsCopy.removeLast() guard let attachment = TSAttachmentStream.fetch(uniqueId: attachmentId) else { - Logger.warn("\(TAG) could not load attachment.") + Logger.warn("\(logTag) could not load attachment.") // Not necessarily an error. // The attachment might have been deleted since the job began. // Continue trying to restore the other attachments. @@ -78,9 +80,9 @@ public class OWSBackupLazyRestoreJob: NSObject { backupIO: backupIO, completion: { (success) in if success { - Logger.info("\(self.TAG) restored attachment.") + Logger.info("\(self.logTag) restored attachment.") } else { - Logger.warn("\(self.TAG) could not restore attachment.") + Logger.warn("\(self.logTag) could not restore attachment.") } // Continue trying to restore the other attachments. self.tryToRestoreNextAttachment(attachmentIds: attachmentIdsCopy, backupIO: backupIO) diff --git a/SignalServiceKit/src/Messages/Attachments/TSAttachmentStream.m b/SignalServiceKit/src/Messages/Attachments/TSAttachmentStream.m index d1f958315..21fd4cc61 100644 --- a/SignalServiceKit/src/Messages/Attachments/TSAttachmentStream.m +++ b/SignalServiceKit/src/Messages/Attachments/TSAttachmentStream.m @@ -362,7 +362,7 @@ NS_ASSUME_NONNULL_BEGIN } if (![[NSFileManager defaultManager] fileExistsAtPath:self.mediaURL.path]) { - OWSFail(@"%@ while generating thumbnail, source file doesn't exist: %@", self.logTag, self.mediaURL); + DDLogError(@"%@ while generating thumbnail, source file doesn't exist: %@", self.logTag, self.mediaURL); return; } @@ -649,6 +649,8 @@ NS_ASSUME_NONNULL_BEGIN [attachment setLazyRestoreFragmentId:nil]; }]; }]; + + [self ensureThumbnail]; } @end diff --git a/SignalServiceKit/src/Storage/TSDatabaseView.m b/SignalServiceKit/src/Storage/TSDatabaseView.m index 3a623605f..245cc5657 100644 --- a/SignalServiceKit/src/Storage/TSDatabaseView.m +++ b/SignalServiceKit/src/Storage/TSDatabaseView.m @@ -389,7 +389,7 @@ NSString *const TSLazyRestoreAttachmentsGroup = @"TSLazyRestoreAttachmentsGroup" options.allowedCollections = [[YapWhitelistBlacklist alloc] initWithWhitelist:[NSSet setWithObject:[TSAttachment collection]]]; YapDatabaseView *view = - [[YapDatabaseAutoView alloc] initWithGrouping:viewGrouping sorting:viewSorting versionTag:@"1" options:options]; + [[YapDatabaseAutoView alloc] initWithGrouping:viewGrouping sorting:viewSorting versionTag:@"2" options:options]; [storage asyncRegisterExtension:view withName:TSLazyRestoreAttachmentsDatabaseViewExtensionName]; }