Bläddra i källkod

put migration logic behind feature flag

Neeraj Gupta 3 år sedan
förälder
incheckning
5c5fa2735b

+ 1 - 0
lib/core/constants.dart

@@ -36,4 +36,5 @@ class FFDefault {
   static const bool enableStripe = true;
   static const bool disableUrlSharing = false;
   static const bool disableCFWorker = false;
+  static const bool enableMissingLocationMigration = false;
 }

+ 19 - 1
lib/services/feature_flag_service.dart

@@ -58,6 +58,19 @@ class FeatureFlagService {
     }
   }
 
+  bool enableMissingLocationMigration() {
+    // only needs to be enabled for android
+    if (!Platform.isAndroid) {
+      return false;
+    }
+    try {
+      return _getFeatureFlags().enableMissingLocationMigration;
+    } catch (e) {
+      _logger.severe(e);
+      return FFDefault.enableMissingLocationMigration;
+    }
+  }
+
   bool enableStripe() {
     if (Platform.isIOS) {
       return false;
@@ -95,11 +108,13 @@ class FeatureFlags {
   final bool disableCFWorker;
   final bool disableUrlSharing;
   final bool enableStripe;
+  final bool enableMissingLocationMigration;
 
   FeatureFlags({
     @required this.disableCFWorker,
     @required this.disableUrlSharing,
     @required this.enableStripe,
+    @required this.enableMissingLocationMigration;
   });
 
   Map<String, dynamic> toMap() {
@@ -107,6 +122,7 @@ class FeatureFlags {
       "disableCFWorker": disableCFWorker,
       "disableUrlSharing": disableUrlSharing,
       "enableStripe": enableStripe,
+      "enableMissingLocationMigration": enableMissingLocationMigration,
     };
   }
 
@@ -119,8 +135,10 @@ class FeatureFlags {
     return FeatureFlags(
       disableCFWorker: json["disableCFWorker"] ?? FFDefault.disableCFWorker,
       disableUrlSharing:
-          json["disableUrlSharing"] ?? FFDefault.disableUrlSharing,
+      json["disableUrlSharing"] ?? FFDefault.disableUrlSharing,
       enableStripe: json["enableStripe"] ?? FFDefault.enableStripe,
+      enableMissingLocationMigration: json["enableMissingLocationMigration"] ??
+          FFDefault.enableMissingLocationMigration,
     );
   }
 

+ 5 - 8
lib/services/file_migration_service.dart

@@ -36,18 +36,15 @@ class FileMigrationService {
   }
 
   bool isLocationMigrationCompleted() {
-    if (!Platform.isAndroid) {
-      return true;
-    }
     return _prefs.get(isLocationMigrationComplete) ?? false;
   }
 
   Future<void> runMigration() async {
     if (_existingMigration != null) {
-      _logger.info("Migration is already in progress, skipping");
+      _logger.info("migration is already in progress, skipping");
       return _existingMigration.future;
     }
-    _logger.info("Start file migration");
+    _logger.info("start migration");
     _existingMigration = Completer<void>();
     try {
       await _runMigrationForFilesWithMissingLocation();
@@ -77,12 +74,12 @@ class FileMigrationService {
     final d = Duration(microseconds: eTime - sTime);
     await _markLocationMigrationAsCompleted();
     _logger.info(
-        'location migration completed in ${d.inSeconds.toString()} seconds');
+        'filesWithMissingLocation migration completed in ${d.inSeconds.toString()} seconds');
   }
 
   Future<void> _checkAndMarkFilesForReUpload(
       List<String> localIDsToProcess) async {
-    _logger.info("Files to process ${localIDsToProcess.length}");
+    _logger.info("files to process ${localIDsToProcess.length}");
     var localIDsWithLocation = <String>[];
     for (var localID in localIDsToProcess) {
       bool hasLocation = false;
@@ -105,7 +102,7 @@ class FileMigrationService {
         localIDsWithLocation.add(localID);
       }
     }
-    _logger.info('Marking ${localIDsWithLocation.length} files for re-upload');
+    _logger.info('marking ${localIDsWithLocation.length} files for re-upload');
     // await _filesDB.markForReUploadIfLocationMissing(localIDsWithLocation);
     await _filesMigrationDB.deleteByLocalIDs(localIDsToProcess);
   }

+ 3 - 2
lib/services/remote_sync_service.dart

@@ -16,6 +16,7 @@ import 'package:photos/models/file.dart';
 import 'package:photos/models/file_type.dart';
 import 'package:photos/services/app_lifecycle_service.dart';
 import 'package:photos/services/collections_service.dart';
+import 'package:photos/services/feature_flag_service.dart';
 import 'package:photos/services/file_migration_service.dart';
 import 'package:photos/services/ignored_files_service.dart';
 import 'package:photos/services/local_sync_service.dart';
@@ -131,8 +132,8 @@ class RemoteSyncService {
     if (!_hasReSynced()) {
       await _markReSyncAsDone();
     }
-    if (Platform.isAndroid &&
-        _fileMigrationService.isLocationMigrationCompleted()) {
+    if (FeatureFlagService.instance.enableMissingLocationMigration() &&
+        !_fileMigrationService.isLocationMigrationCompleted()) {
       _fileMigrationService.runMigration();
     }
   }