Neeraj Gupta 2 лет назад
Родитель
Сommit
a5a135a611
2 измененных файлов с 23 добавлено и 24 удалено
  1. 14 14
      lib/services/local/local_sync_util.dart
  2. 9 10
      lib/services/local_sync_service.dart

+ 14 - 14
lib/services/local/local_sync_util.dart

@@ -110,7 +110,7 @@ Future<List<LocalPathAsset>> getAllLocalAssets() async {
   return localPathAssets;
 }
 
-Future<LocalUnSyncResult> getLocalUnSyncedFiles(
+Future<LocalDiffResult> getDiffWithLocal(
   List<LocalPathAsset> assets,
   // current set of assets available on device
   Set<String> existingIDs, // localIDs of files already imported in app
@@ -123,20 +123,20 @@ Future<LocalUnSyncResult> getLocalUnSyncedFiles(
   args['existingIDs'] = existingIDs;
   args['invalidIDs'] = invalidIDs;
   args['pathToLocalIDs'] = pathToLocalIDs;
-  final LocalUnSyncResult localUnSyncResult =
-      await computer.compute(_getUnsyncedAssets, param: args);
-  if (localUnSyncResult.localPathAssets.isEmpty) {
-    return localUnSyncResult;
+  final LocalDiffResult diffResult =
+      await computer.compute(_getLocalAssetsDiff, param: args);
+  if (diffResult.localPathAssets.isEmpty) {
+    return diffResult;
   }
   final unSyncedFiles =
-      await _convertLocalAssetsToUniqueFiles(localUnSyncResult.localPathAssets);
-  localUnSyncResult.uniqueLocalFiles = unSyncedFiles;
-  return localUnSyncResult;
+      await _convertLocalAssetsToUniqueFiles(diffResult.localPathAssets);
+  diffResult.uniqueLocalFiles = unSyncedFiles;
+  return diffResult;
 }
 
-// _getUnsyncedAssets performs following operation
-// Identify
-LocalUnSyncResult _getUnsyncedAssets(Map<String, dynamic> args) {
+// _getLocalAssetsDiff compares local db with the file system and compute
+// the files which needs to be added or removed from device collection.
+LocalDiffResult _getLocalAssetsDiff(Map<String, dynamic> args) {
   final List<LocalPathAsset> onDeviceLocalPathAsset = args['assets'];
   final Set<String> existingIDs = args['existingIDs'];
   final Set<String> invalidIDs = args['invalidIDs'];
@@ -176,7 +176,7 @@ LocalUnSyncResult _getUnsyncedAssets(Map<String, dynamic> args) {
       unsyncedAssets.add(localPathAsset);
     }
   }
-  return LocalUnSyncResult(
+  return LocalDiffResult(
     localPathAssets: unsyncedAssets,
     newPathToLocalIDs: newPathToLocalIDs,
     deletePathToLocalIDs: removedPathToLocalIDs,
@@ -307,7 +307,7 @@ class LocalPathAsset {
   });
 }
 
-class LocalUnSyncResult {
+class LocalDiffResult {
   // unique localPath Assets.
   final List<LocalPathAsset> localPathAssets;
 
@@ -320,7 +320,7 @@ class LocalUnSyncResult {
 
   final Map<String, Set<String>> deletePathToLocalIDs;
 
-  LocalUnSyncResult({
+  LocalDiffResult({
     this.uniqueLocalFiles,
     this.localPathAssets,
     this.newPathToLocalIDs,

+ 9 - 10
lib/services/local_sync_service.dart

@@ -154,7 +154,7 @@ class LocalSyncService {
     final Map<String, Set<String>> pathToLocalIDs =
         await _db.getDevicePathIDToLocalIDMap();
     final invalidIDs = _getInvalidFileIDs().toSet();
-    final localUnSyncResult = await getLocalUnSyncedFiles(
+    final localDiffResult = await getDiffWithLocal(
       localAssets,
       existingLocalFileIDs,
       pathToLocalIDs,
@@ -162,25 +162,24 @@ class LocalSyncService {
       _computer,
     );
     bool hasAnyMappingChanged = false;
-    if (localUnSyncResult.newPathToLocalIDs?.isNotEmpty ?? false) {
-      await _db
-          .insertPathIDToLocalIDMapping(localUnSyncResult.newPathToLocalIDs);
+    if (localDiffResult.newPathToLocalIDs?.isNotEmpty ?? false) {
+      await _db.insertPathIDToLocalIDMapping(localDiffResult.newPathToLocalIDs);
       hasAnyMappingChanged = true;
     }
-    if (localUnSyncResult.deletePathToLocalIDs?.isNotEmpty ?? false) {
+    if (localDiffResult.deletePathToLocalIDs?.isNotEmpty ?? false) {
       await _db
-          .deletePathIDToLocalIDMapping(localUnSyncResult.deletePathToLocalIDs);
+          .deletePathIDToLocalIDMapping(localDiffResult.deletePathToLocalIDs);
       hasAnyMappingChanged = true;
     }
     final bool hasUnsyncedFiles =
-        localUnSyncResult.uniqueLocalFiles?.isNotEmpty ?? false;
+        localDiffResult.uniqueLocalFiles?.isNotEmpty ?? false;
     if (hasUnsyncedFiles) {
       await _db.insertMultiple(
-        localUnSyncResult.uniqueLocalFiles,
+        localDiffResult.uniqueLocalFiles,
         conflictAlgorithm: ConflictAlgorithm.ignore,
       );
       _logger.info(
-        "Inserted ${localUnSyncResult.uniqueLocalFiles.length} "
+        "Inserted ${localDiffResult.uniqueLocalFiles.length} "
         "un-synced files",
       );
     }
@@ -190,7 +189,7 @@ class LocalSyncService {
     );
     if (hasAnyMappingChanged || hasUnsyncedFiles) {
       Bus.instance.fire(
-        LocalPhotosUpdatedEvent(localUnSyncResult.uniqueLocalFiles),
+        LocalPhotosUpdatedEvent(localDiffResult.uniqueLocalFiles),
       );
     }
     _logger.info("syncAll took ${stopwatch.elapsed.inMilliseconds}ms ");