From a0bd2c2324c9ef64c48813606659481cd02061f6 Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Mon, 19 Mar 2018 12:36:21 -0400 Subject: [PATCH] OrphanDataCleaner shouldn't delete active thumbnails // FREEBIE --- Signal/src/ViewControllers/MediaGalleryViewController.swift | 2 +- Signal/src/ViewControllers/MediaTileViewController.swift | 4 ++-- .../src/Messages/Attachments/TSAttachmentStream.h | 6 +----- SignalServiceKit/src/Storage/OWSOrphanedDataCleaner.m | 5 +++++ 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/Signal/src/ViewControllers/MediaGalleryViewController.swift b/Signal/src/ViewControllers/MediaGalleryViewController.swift index 6f331c84a..dfd3764a9 100644 --- a/Signal/src/ViewControllers/MediaGalleryViewController.swift +++ b/Signal/src/ViewControllers/MediaGalleryViewController.swift @@ -26,7 +26,7 @@ public struct MediaGalleryItem: Equatable { } var thumbnailImage: UIImage { - guard let image = attachmentStream.thumbnailImage else { + guard let image = attachmentStream.thumbnailImage() else { owsFail("\(logTag) in \(#function) unexpectedly unable to build attachment thumbnail") return UIImage() } diff --git a/Signal/src/ViewControllers/MediaTileViewController.swift b/Signal/src/ViewControllers/MediaTileViewController.swift index 0769f7029..c5ee4fc53 100644 --- a/Signal/src/ViewControllers/MediaTileViewController.swift +++ b/Signal/src/ViewControllers/MediaTileViewController.swift @@ -268,8 +268,8 @@ public class MediaTileViewController: UICollectionViewController, MediaGalleryCe // MARK: Lazy Loading // This should be substantially larger than one screen size so we don't have to call it - // multiple times in a rapid succession. - let kMediaTileViewLoadBatchSize: UInt = 200 + // multiple times in a rapid succession, but not so large that loading more get's chopping + let kMediaTileViewLoadBatchSize: UInt = 80 var oldestLoadedItem: MediaGalleryItem? { guard let oldestDate = galleryDates.first else { return nil diff --git a/SignalServiceKit/src/Messages/Attachments/TSAttachmentStream.h b/SignalServiceKit/src/Messages/Attachments/TSAttachmentStream.h index 8b10fa276..1349a34e0 100644 --- a/SignalServiceKit/src/Messages/Attachments/TSAttachmentStream.h +++ b/SignalServiceKit/src/Messages/Attachments/TSAttachmentStream.h @@ -29,11 +29,6 @@ NS_ASSUME_NONNULL_BEGIN // messages received from other clients @property (nullable, nonatomic) NSData *digest; -// A serialized image which lives in the db, accessible without additional disk access. -// This is useful for the gallery view which allows us to fetch potentially many -// attachments in a single read. -@property (nullable, readonly) UIImage *thumbnailImage; - // This only applies for attachments being uploaded. @property (atomic) BOOL isUploaded; @@ -51,6 +46,7 @@ NS_ASSUME_NONNULL_BEGIN - (nullable NSURL *)mediaURL; - (nullable NSString *)filePath; +- (nullable NSString *)thumbnailPath; - (nullable NSData *)readDataFromFileWithError:(NSError **)error; - (BOOL)writeData:(NSData *)data error:(NSError **)error; diff --git a/SignalServiceKit/src/Storage/OWSOrphanedDataCleaner.m b/SignalServiceKit/src/Storage/OWSOrphanedDataCleaner.m index 128b4cf14..19254a240 100644 --- a/SignalServiceKit/src/Storage/OWSOrphanedDataCleaner.m +++ b/SignalServiceKit/src/Storage/OWSOrphanedDataCleaner.m @@ -73,6 +73,11 @@ NS_ASSUME_NONNULL_BEGIN NSString *_Nullable filePath = [attachmentStream filePath]; OWSAssert(filePath); [attachmentFilePaths addObject:filePath]; + + NSString *_Nullable thumbnailPath = [attachmentStream thumbnailPath]; + if (thumbnailPath.length > 0) { + [attachmentFilePaths addObject:thumbnailPath]; + } }]; }];