π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mob][photos] Revert self-inflicted update guard
AmanRajSinghMouryad14cb799c22a
diff --git a/mobile/apps/photos/lib/services/sync/local_sync_service.dart b/mobile/apps/photos/lib/services/sync/local_sync_service.dartindex 4902c73ab2..6461972a1e 100644--- a/mobile/apps/photos/lib/services/sync/local_sync_service.dart+++ b/mobile/apps/photos/lib/services/sync/local_sync_service.dart@@ -30,13 +30,10 @@ import "package:shared_preferences/shared_preferences.dart";import "package:synchronized/synchronized.dart";import "package:tuple/tuple.dart";-// Tracks iOS assets whose origin bytes were recently fetched for upload or-// ML, mapped to the asset's modificationTime (in microseconds) at fetch time.-// Fetching origin bytes can itself fire a photo library change notification;-// such self-inflicted notifications carry an unchanged modificationTime and-// are skipped during update tracking. A real edit moves modificationTime-// forward, so it is always tracked even when the localID is present here.-final LRUMap<String, int> trackOriginFetchForUploadOrML = LRUMap(200);+// This map is used to track if a iOS origin file is being fetched for uploading+// or ML processing. In such cases, we want to ignore these files if they come in response+// from the local sync service. When a file is download+final LRUMap<String, bool> trackOriginFetchForUploadOrML = LRUMap(200);class LocalSyncService {final _logger = Logger("LocalSyncService");@@ -398,7 +395,10 @@ class LocalSyncService {if (allFiles.isEmpty) return;final bool discoveredNewFiles = newlyInsertedFiles.isNotEmpty;if (!discoveredNewFiles) {- allFiles.removeWhere(_isSelfInflictedUpdate);+ allFiles.removeWhere(+ (file) =>+ trackOriginFetchForUploadOrML.get(file.localID ?? '') ?? false,+ );if (allFiles.isEmpty) {_logger.info("skipping firing LocalPhotosUpdatedEvent as no new files");return;@@ -429,60 +429,32 @@ class LocalSyncService {List<EnteFile> files,Set<String> existingLocalFileIDs,) async {- final List<EnteFile> updatedFiles = files+ final List<String> updatedLocalIDs = files.where((file) =>file.localID != null &&existingLocalFileIDs.contains(file.localID),)+ .map((e) => e.localID!).toList();- if (updatedFiles.isNotEmpty) {- final int updateCount = updatedFiles.length;- updatedFiles.removeWhere(- (file) => _isSelfInflictedUpdate(file, logDecision: true),+ if (updatedLocalIDs.isNotEmpty) {+ final int updateCount = updatedLocalIDs.length;+ updatedLocalIDs.removeWhere(+ (x) => trackOriginFetchForUploadOrML.get(x) ?? false,);_logger.info(- "track ${updatedFiles.length}/ $updateCount files due to modification change",+ "track ${updatedLocalIDs.length}/ $updateCount files due to modification change",);- if (updatedFiles.isNotEmpty) {+ if (updatedLocalIDs.isNotEmpty) {await FileUpdationDB.instance.insertMultiple(- updatedFiles.map((e) => e.localID!).toList(),+ updatedLocalIDs,FileUpdationDB.modificationTimeUpdated,);}}}- // A change notification for a file whose modificationTime still matches the- // value recorded when we last fetched its origin bytes was caused by that- // fetch itself, not by a user edit.- bool _isSelfInflictedUpdate(EnteFile file, {bool logDecision = false}) {- final int? trackedModificationTime = trackOriginFetchForUploadOrML.get(- file.localID ?? '',- );- if (trackedModificationTime == null) {- return false;- }- final bool isSelfInflicted =- trackedModificationTime == file.modificationTime;- if (logDecision) {- if (isSelfInflicted) {- _logger.info(- "Skipping self-inflicted update for ${file.localID}, "- "modificationTime unchanged at $trackedModificationTime",- );- } else {- _logger.info(- "Tracking edit of recently fetched ${file.localID}, "- "modificationTime moved $trackedModificationTime -> "- "${file.modificationTime}",- );- }- }- return isSelfInflicted;- }-void _registerChangeCallback() {if (_isChangeCallbackRegistered) {return;diff --git a/mobile/apps/photos/lib/utils/file_uploader_util.dart b/mobile/apps/photos/lib/utils/file_uploader_util.dartindex db0edbfb23..4e12dc46ef 100644--- a/mobile/apps/photos/lib/utils/file_uploader_util.dart+++ b/mobile/apps/photos/lib/utils/file_uploader_util.dart@@ -130,10 +130,7 @@ Future<MediaUploadData> _getMediaUploadDataFromAssetFile(}_assertFileType(asset, file);if (Platform.isIOS) {- trackOriginFetchForUploadOrML.put(- file.localID!,- asset.modifiedDateTime.microsecondsSinceEpoch,- );+ trackOriginFetchForUploadOrML.put(file.localID!, true);}try {sourceFile = await asset.originFilediff --git a/mobile/apps/photos/lib/utils/ml_util.dart b/mobile/apps/photos/lib/utils/ml_util.dartindex d109436ce4..829f7a2c87 100644--- a/mobile/apps/photos/lib/utils/ml_util.dart+++ b/mobile/apps/photos/lib/utils/ml_util.dart@@ -722,13 +722,7 @@ Future<String> getImagePathForML(EnteFile enteFile) async {}try {if (Platform.isIOS && enteFile.localID != null) {- final asset = await enteFile.getAsset;- if (asset != null) {- trackOriginFetchForUploadOrML.put(- enteFile.localID!,- asset.modifiedDateTime.microsecondsSinceEpoch,- );- }+ trackOriginFetchForUploadOrML.put(enteFile.localID!, true);}file = await getFile(enteFile, isOrigin: true);} catch (e, s) {