Forráskód Böngészése

improve local photo visiblity on import

Neeraj Gupta 2 éve
szülő
commit
ef924f1545

+ 0 - 1
lib/services/local_sync_service.dart

@@ -360,7 +360,6 @@ class LocalSyncService {
         conflictAlgorithm: ConflictAlgorithm.ignore,
       );
       _logger.info("Inserted " + files.length.toString() + " files.");
-      // _updatePathsToBackup(files);
       Bus.instance.fire(LocalPhotosUpdatedEvent(allFiles));
     }
     await _prefs.setInt(kDbUpdationTimeKey, toTime);

+ 16 - 3
lib/services/remote_sync_service.dart

@@ -49,6 +49,7 @@ class RemoteSyncService {
   bool _existingSyncSilent = false;
 
   static const kHasSyncedArchiveKey = "has_synced_archive";
+  final String _isFirstRemoteSyncDone = "isFirstRemoteSyncDone";
 
   // 28 Sept, 2021 9:03:20 AM IST
   static const kArchiveFeatureReleaseTime = 1632800000000000;
@@ -94,6 +95,15 @@ class RemoteSyncService {
     _existingSyncSilent = silently;
 
     try {
+      // use flag to decide if we should start marking files for upload before
+      // remote-sync is done. This is done to avoid adding existing files to
+      // the same or different collection when user had already uploaded them
+      // before.
+      final bool hasSyncedBefore =
+          _prefs.containsKey(_isFirstRemoteSyncDone) ?? false;
+      if (hasSyncedBefore) {
+        await syncDeviceCollectionFilesForUpload();
+      }
       await _pullDiff();
       // sync trash but consume error during initial launch.
       // this is to ensure that we don't pause upload due to any error during
@@ -102,14 +112,17 @@ class RemoteSyncService {
       await TrashSyncService.instance
           .syncTrash()
           .onError((e, s) => _logger.severe('trash sync failed', e, s));
-      await _syncDeviceCollectionFilesForUpload();
+      if (!hasSyncedBefore) {
+        await _prefs.setBool(_isFirstRemoteSyncDone, true);
+        await syncDeviceCollectionFilesForUpload();
+      }
       final filesToBeUploaded = await _getFilesToBeUploaded();
       final hasUploadedFiles = await _uploadFiles(filesToBeUploaded);
       if (hasUploadedFiles) {
         await _pullDiff();
         _existingSync.complete();
         _existingSync = null;
-        await _syncDeviceCollectionFilesForUpload();
+        await syncDeviceCollectionFilesForUpload();
         final hasMoreFilesToBackup = (await _getFilesToBeUploaded()).isNotEmpty;
         if (hasMoreFilesToBackup && !_shouldThrottleSync()) {
           // Skipping a resync to ensure that files that were ignored in this
@@ -232,7 +245,7 @@ class RemoteSyncService {
     }
   }
 
-  Future<void> _syncDeviceCollectionFilesForUpload() async {
+  Future<void> syncDeviceCollectionFilesForUpload() async {
     final int ownerID = _config.getUserID();
     final deviceCollections = await _db.getDeviceCollections();
     deviceCollections.removeWhere((element) => !element.shouldBackup);

+ 5 - 2
lib/services/search_service.dart

@@ -293,8 +293,11 @@ class SearchService {
       );
       if (matchedFiles.isNotEmpty) {
         searchResults.add(
-          GenericSearchResult(ResultType.event,
-              '$day ${potentialDate.item2.name} ${year ?? ''}', matchedFiles),
+          GenericSearchResult(
+            ResultType.event,
+            '$day ${potentialDate.item2.name} ${year ?? ''}',
+            matchedFiles,
+          ),
         );
       }
     }