π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Improve live photos change check
Neeraj Gupta1d9d96faf166
diff --git a/lib/db/file_updation_db.dart b/lib/db/file_updation_db.dartindex 656f8ed176..dd12b5f2ed 100644--- a/lib/db/file_updation_db.dart+++ b/lib/db/file_updation_db.dart@@ -14,7 +14,7 @@ class FileUpdationDB {static const tableName = 're_upload_tracker';static const columnLocalID = 'local_id';static const columnReason = 'reason';- static const livePhotoSize = 'livePhotoSize';+ static const livePhotoCheck = 'livePhotoCheck';static const modificationTimeUpdated = 'modificationTimeUpdated';diff --git a/lib/db/files_db.dart b/lib/db/files_db.dartindex 0bb1f99e3c..eea060855e 100644--- a/lib/db/files_db.dart+++ b/lib/db/files_db.dart@@ -1449,20 +1449,16 @@ class FilesDB {return result;}- // For a given userID, return unique uploadedFileId for the given userID- Future<List<String>> getLivePhotosWithBadSize(- int userId,- int sizeInBytes,- ) async {+ // For a given userID, return unique localID for all uploaded live photos+ Future<List<String>> getLivePhotosForUser(int userId) async {final db = await instance.database;final rows = await db.query(filesTable,columns: [columnLocalID],distinct: true,where: '$columnOwnerID = ? AND '- '($columnFileSize IS NULL OR $columnFileSize = ?) AND ''$columnFileType = ? AND $columnLocalID IS NOT NULL',- whereArgs: [userId, sizeInBytes, getInt(FileType.livePhoto)],+ whereArgs: [userId, getInt(FileType.livePhoto)],);final result = <String>[];for (final row in rows) {diff --git a/lib/services/local_file_update_service.dart b/lib/services/local_file_update_service.dartindex 49b8cd45bc..2b2a40f76f 100644--- a/lib/services/local_file_update_service.dart+++ b/lib/services/local_file_update_service.dart@@ -21,9 +21,9 @@ class LocalFileUpdateService {late FileUpdationDB _fileUpdationDB;late SharedPreferences _prefs;late Logger _logger;- final String _iosLivePhotoSizeMigrationDone = 'fm_ios_live_photo_size';- final String _doneLivePhotoImport = 'fm_import_ios_live_photo_size';- static int fourMBWithChunkSize = 4194338;+ final String _iosLivePhotoSizeMigrationDone = 'fm_ios_live_photo_check';+ final String _doneLivePhotoImport = 'fm_import_ios_live_photo_check';+ static int twoHundredKb = 200 * 1024;final List<String> _oldMigrationKeys = ['fm_badCreationTime','fm_badCreationTimeCompleted',@@ -31,6 +31,8 @@ class LocalFileUpdateService {'fm_missingLocationV2MigrationDone','fm_badLocationImportDone','fm_badLocationMigrationDone',+ 'fm_ios_live_photo_size',+ 'fm_import_ios_live_photo_size',];Completer<void>? _existingMigration;@@ -55,9 +57,8 @@ class LocalFileUpdateService {_existingMigration = Completer<void>();try {await _markFilesWhichAreActuallyUpdated();- if (Platform.isAndroid) {- _cleanUpOlderMigration().ignore();- } else {+ _cleanUpOlderMigration().ignore();+ if (!Platform.isAndroid) {await _handleLivePhotosSizedCheck();}} catch (e, s) {@@ -78,15 +79,16 @@ class LocalFileUpdateService {}}if (hasOldMigrationKey) {- for (var element in _oldMigrationKeys) {- _prefs.remove(element);- }await _fileUpdationDB.deleteByReasons(['missing_location','badCreationTime','missingLocationV2','badLocationCord',+ 'livePhotoSize',]);+ for (var element in _oldMigrationKeys) {+ await _prefs.remove(element);+ }}}@@ -220,7 +222,7 @@ class LocalFileUpdateService {final localIDsToProcess =await _fileUpdationDB.getLocalIDsForPotentialReUpload(singleRunLimit,- FileUpdationDB.livePhotoSize,+ FileUpdationDB.livePhotoCheck,);if (localIDsToProcess.isNotEmpty) {await _checkLivePhotoWithLowOrUnknownSize(@@ -233,7 +235,7 @@ class LocalFileUpdateService {'completed in ${d.inSeconds.toString()} secs',);} else {- _prefs.setBool(_iosLivePhotoSizeMigrationDone, true);+ await _prefs.setBool(_iosLivePhotoSizeMigrationDone, true);}} catch (e, s) {_logger.severe('error while checking livePhotoSize check', e, s);@@ -283,9 +285,6 @@ class LocalFileUpdateService {continue;} else if (file.fileType != FileType.livePhoto) {_logger.severe('fileType is not livePhoto, skip this file');- continue;- } else if (file.fileSize! != fourMBWithChunkSize) {- // back-filled size is not of our interestprocessedIDs.add(file.localID!);continue;}@@ -293,20 +292,24 @@ class LocalFileUpdateService {continue;}try {- final MediaUploadData uploadData = await getUploadData(file);- _logger.info(- 'Found livePhoto on local with hash ${uploadData.hashData?.fileHash ?? "null"} and existing hash ${file.hash ?? "null"}',- );- await clearCache(file);- await FilesDB.instance.markFilesForReUpload(- userID,- file.localID!,- file.title,- file.location,- file.creationTime!,- file.modificationTime!,- file.fileType,- );+ late MediaUploadData uploadData;+ late int mediaUploadSize;+ (uploadData, mediaUploadSize) = await getUploadDataWithSizeSize(file);+ if ((file.fileSize! - mediaUploadSize).abs() > twoHundredKb) {+ _logger.info(+ 'Re-upload livePhoto localHash ${uploadData.hashData?.fileHash ?? "null"} & localSize: $mediaUploadSize'+ ' and remoteHash ${file.hash ?? "null"} & removeSize: ${file.fileSize!}',+ );+ await FilesDB.instance.markFilesForReUpload(+ userID,+ file.localID!,+ file.title,+ file.location,+ file.creationTime!,+ file.modificationTime!,+ file.fileType,+ );+ }processedIDs.add(file.localID!);} on InvalidFileError catch (e) {if (e.reason == InvalidReason.livePhotoToImageTypeChanged ||@@ -324,9 +327,10 @@ class LocalFileUpdateService {_logger.severe("livePhoto check failed", e);} finally {}}+ _logger.info('completed check for ${localIDsToProcess.length} files');await _fileUpdationDB.deleteByLocalIDs(processedIDs.toList(),- FileUpdationDB.livePhotoSize,+ FileUpdationDB.livePhotoCheck,);}@@ -337,11 +341,11 @@ class LocalFileUpdateService {_logger.info('_importLivePhotoReUploadCandidates');final EnteWatch watch = EnteWatch("_importLivePhotoReUploadCandidates");final int ownerID = Configuration.instance.getUserID()!;- final List<String> localIDs = await FilesDB.instance- .getLivePhotosWithBadSize(ownerID, fourMBWithChunkSize);+ final List<String> localIDs =+ await FilesDB.instance.getLivePhotosForUser(ownerID);await _fileUpdationDB.insertMultiple(localIDs,- FileUpdationDB.livePhotoSize,+ FileUpdationDB.livePhotoCheck,);watch.log("imported ${localIDs.length} files");await _prefs.setBool(_doneLivePhotoImport, true);@@ -357,4 +361,18 @@ class LocalFileUpdateService {}return mediaUploadData;}++ Future<(MediaUploadData, int)> getUploadDataWithSizeSize(+ EnteFile file,+ ) async {+ final mediaUploadData = await getUploadDataFromEnteFile(file);+ final int size = await mediaUploadData.sourceFile!.length();+ // delete the file from app's internal cache if it was copied to app+ // for upload. Shared Media should only be cleared when the upload+ // succeeds.+ if (Platform.isIOS && mediaUploadData.sourceFile != null) {+ await mediaUploadData.sourceFile?.delete();+ }+ return (mediaUploadData, size);+ }}