Переглянути джерело

mark variables as final when possible

Neeraj Gupta 2 роки тому
батько
коміт
2bbacb26ee

+ 10 - 9
lib/db/device_files_db.dart

@@ -22,7 +22,7 @@ extension DeviceFiles on FilesDB {
     var batch = db.batch();
     int batchCounter = 0;
     for (MapEntry e in mappingToAdd.entries) {
-      String pathID = e.key;
+      final String pathID = e.key;
       for (String localID in e.value) {
         if (batchCounter == 400) {
           await batch.commit(noResult: true);
@@ -44,13 +44,14 @@ extension DeviceFiles on FilesDB {
   }
 
   Future<void> deletePathIDToLocalIDMapping(
-      Map<String, Set<String>> mappingsToRemove) async {
+    Map<String, Set<String>> mappingsToRemove,
+  ) async {
     debugPrint("removing PathIDToLocalIDMapping");
     final db = await database;
     var batch = db.batch();
     int batchCounter = 0;
     for (MapEntry e in mappingsToRemove.entries) {
-      String pathID = e.key;
+      final String pathID = e.key;
       for (String localID in e.value) {
         if (batchCounter == 400) {
           await batch.commit(noResult: true);
@@ -171,9 +172,9 @@ extension DeviceFiles on FilesDB {
       final Database db = await database;
       final Set<String> existingPathIds = await getDevicePathIDs();
       for (Tuple2<AssetPathEntity, String> tup in devicePathInfo) {
-        AssetPathEntity pathEntity = tup.item1;
-        String localID = tup.item2;
-        bool shouldUpdate = existingPathIds.contains(pathEntity.id);
+        final AssetPathEntity pathEntity = tup.item1;
+        final String localID = tup.item2;
+        final bool shouldUpdate = existingPathIds.contains(pathEntity.id);
         if (shouldUpdate) {
           await db.rawUpdate(
             "UPDATE device_path_collections SET name = ?, cover_id = ?, count"
@@ -224,7 +225,7 @@ extension DeviceFiles on FilesDB {
     var batch = db.batch();
     int batchCounter = 0;
     for (MapEntry e in syncStatus.entries) {
-      String pathID = e.key;
+      final String pathID = e.key;
       if (batchCounter == 400) {
         await batch.commit(noResult: true);
         batch = db.batch();
@@ -266,7 +267,7 @@ extension DeviceFiles on FilesDB {
   }) async {
     final db = await database;
     final order = (asc ?? false ? 'ASC' : 'DESC');
-    String rawQuery = '''
+    final String rawQuery = '''
     SELECT *
           FROM ${FilesDB.filesTable}
           WHERE ${FilesDB.columnLocalID} IS NOT NULL AND
@@ -296,7 +297,7 @@ extension DeviceFiles on FilesDB {
       );
       final List<DevicePathCollection> deviceCollections = [];
       for (var row in devicePathRows) {
-        DevicePathCollection devicePathCollection = DevicePathCollection(
+        final DevicePathCollection devicePathCollection = DevicePathCollection(
           row["id"],
           row['name'],
           count: row['count'],

+ 1 - 1
lib/db/file_updation_db.dart

@@ -132,7 +132,7 @@ class FileUpdationDB {
     String reason,
   ) async {
     final db = await instance.database;
-    String whereClause = '$columnReason = "$reason"';
+    final String whereClause = '$columnReason = "$reason"';
     final rows = await db.query(
       tableName,
       limit: limit,

+ 2 - 2
lib/db/files_db.dart

@@ -336,9 +336,9 @@ class FilesDB {
   Future<void> deleteDB() async {
     if (kDebugMode) {
       debugPrint("Deleting files db");
-      io.Directory documentsDirectory =
+      final io.Directory documentsDirectory =
           await getApplicationDocumentsDirectory();
-      String path = join(documentsDirectory.path, _databaseName);
+      final String path = join(documentsDirectory.path, _databaseName);
       io.File(path).deleteSync(recursive: true);
       _dbFuture = null;
     }

+ 6 - 5
lib/services/ignored_files_service.dart

@@ -48,8 +48,8 @@ class IgnoredFilesService {
   }
 
   Future<void> removeIgnoredMappings(List<File> files) async {
-    List<IgnoredFile> ignoredFiles = [];
-    Set<String> idsToRemoveFromCache = {};
+    final List<IgnoredFile> ignoredFiles = [];
+    final Set<String> idsToRemoveFromCache = {};
     for (var file in files) {
       if (Platform.isIOS && file.localID != null) {
         // in IOS, the imported file might not have title fetched by default.
@@ -58,16 +58,17 @@ class IgnoredFilesService {
           file.title = 'dummyTitle';
         }
       }
-      var ignoredFile = IgnoredFile.fromFile(file);
+      final ignoredFile = IgnoredFile.fromFile(file);
       if (ignoredFile != null) {
         ignoredFiles.add(ignoredFile);
-        var id = _idForIgnoredFile(ignoredFile);
+        final id = _idForIgnoredFile(ignoredFile);
         if (id != null) {
           idsToRemoveFromCache.add(id);
         }
       } else {
         _logger.warning(
-            'ignoredFile should not be null while removing mapping ${file.tag()}');
+          'ignoredFile should not be null while removing mapping ${file.tag()}',
+        );
       }
     }
     if (ignoredFiles.isNotEmpty) {

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

@@ -20,16 +20,16 @@ Future<Tuple2<List<LocalPathAsset>, List<File>>> getLocalPathAssetsAndFiles(
     updateFromTime: fromTime,
     updateToTime: toTime,
   );
-  List<LocalPathAsset> localPathAssets = [];
+  final List<LocalPathAsset> localPathAssets = [];
 
   // alreadySeenLocalIDs is used to track and ignore file with particular
   // localID if it's already present in another album. This only impacts iOS
   // devices where a file can belong to multiple
-  Set<String> alreadySeenLocalIDs = {};
-  List<File> uniqueFiles = [];
+  final Set<String> alreadySeenLocalIDs = {};
+  final List<File> uniqueFiles = [];
   for (AssetPathEntity pathEntity in pathEntities) {
-    List<AssetEntity> assetsInPath = await _getAllAssetLists(pathEntity);
-    Tuple2<Set<String>, List<File>> result = await computer.compute(
+    final List<AssetEntity> assetsInPath = await _getAllAssetLists(pathEntity);
+    final Tuple2<Set<String>, List<File>> result = await computer.compute(
       _getLocalIDsAndFilesFromAssets,
       param: <String, dynamic>{
         "pathEntity": pathEntity,
@@ -58,7 +58,7 @@ Future<Tuple2<List<LocalPathAsset>, List<File>>> getLocalPathAssetsAndFiles(
 // identify (in future) which AssetPath needs to be re-synced again.
 Future<List<Tuple2<AssetPathEntity, String>>>
     getDeviceFolderWithCountAndCoverID() async {
-  List<Tuple2<AssetPathEntity, String>> result = [];
+  final List<Tuple2<AssetPathEntity, String>> result = [];
   final pathEntities = await _getGalleryList(
     needsTitle: false,
     containsModifiedPath: true,
@@ -67,11 +67,11 @@ Future<List<Tuple2<AssetPathEntity, String>>>
   );
   for (AssetPathEntity pathEntity in pathEntities) {
     //todo: test and handle empty album case
-    var latestEntity = await pathEntity.getAssetListPaged(
+    final latestEntity = await pathEntity.getAssetListPaged(
       page: 0,
       size: 1,
     );
-    String localCoverID = latestEntity.first.id;
+    final String localCoverID = latestEntity.first.id;
     result.add(Tuple2(pathEntity, localCoverID));
   }
   return result;
@@ -95,7 +95,7 @@ Future<List<LocalPathAsset>> getAllLocalAssets() async {
   );
   final List<LocalPathAsset> localPathAssets = [];
   for (final assetPath in assetPaths) {
-    Set<String> localIDs = <String>{};
+    final Set<String> localIDs = <String>{};
     for (final asset in await _getAllAssetLists(assetPath)) {
       localIDs.add(asset.id);
     }
@@ -147,12 +147,12 @@ LocalUnSyncResult _getUnsyncedAssets(Map<String, dynamic> args) {
   final List<LocalPathAsset> unsyncedAssets = [];
 
   for (final localPathAsset in onDeviceLocalPathAsset) {
-    String pathID = localPathAsset.pathID;
+    final String pathID = localPathAsset.pathID;
     // Start identifying pathID to localID mapping changes which needs to be
     // synced
-    Set<String> candidateLocalIDsForRemoval =
+    final Set<String> candidateLocalIDsForRemoval =
         pathToLocalIDs[pathID] ?? <String>{};
-    Set<String> missingLocalIDsInPath = <String>{};
+    final Set<String> missingLocalIDsInPath = <String>{};
     for (final String localID in localPathAsset.localIDs) {
       if (candidateLocalIDsForRemoval.contains(localID)) {
         // remove the localID after checking. Any pending existing ID indicates
@@ -189,10 +189,10 @@ Future<List<File>> _convertLocalAssetsToUniqueFiles(
   final Set<String> alreadySeenLocalIDs = <String>{};
   final List<File> files = [];
   for (LocalPathAsset localPathAsset in assets) {
-    String localPathName = localPathAsset.pathName;
+    final String localPathName = localPathAsset.pathName;
     for (final String localID in localPathAsset.localIDs) {
       if (!alreadySeenLocalIDs.contains(localID)) {
-        var assetEntity = await AssetEntity.fromId(localID);
+        final assetEntity = await AssetEntity.fromId(localID);
         files.add(
           await File.fromAsset(localPathName, assetEntity),
         );
@@ -250,7 +250,7 @@ Future<List<AssetPathEntity>> _getGalleryList({
 }
 
 Future<List<AssetEntity>> _getAllAssetLists(AssetPathEntity pathEntity) async {
-  List<AssetEntity> result = [];
+  final List<AssetEntity> result = [];
   int currentPage = 0;
   List<AssetEntity> currentPageResult = [];
   do {
@@ -277,7 +277,7 @@ Future<Tuple2<Set<String>, List<File>>> _getLocalIDsAndFilesFromAssets(
   final Set<String> localIDs = {};
   for (AssetEntity entity in assetList) {
     localIDs.add(entity.id);
-    bool assetCreatedOrUpdatedAfterGivenTime = max(
+    final bool assetCreatedOrUpdatedAfterGivenTime = max(
           entity.createDateTime.microsecondsSinceEpoch,
           entity.modifiedDateTime.microsecondsSinceEpoch,
         ) >

+ 8 - 8
lib/services/local_file_update_service.dart

@@ -97,9 +97,9 @@ class LocalFileUpdateService {
     List<String> localIDsToProcess,
   ) async {
     _logger.info("files to process ${localIDsToProcess.length} for reupload");
-    List<ente.File> localFiles =
+    final List<ente.File> localFiles =
         (await FilesDB.instance.getLocalFiles(localIDsToProcess));
-    Set<String> processedIDs = {};
+    final Set<String> processedIDs = {};
     for (ente.File file in localFiles) {
       if (processedIDs.contains(file.localID)) {
         continue;
@@ -157,14 +157,14 @@ class LocalFileUpdateService {
     }
     // migration only needs to run if Android API Level is 29 or higher
     final int version = int.parse(await PhotoManager.systemVersion());
-    bool isMigrationRequired = version >= 29;
+    final bool isMigrationRequired = version >= 29;
     if (isMigrationRequired) {
       await _importLocalFilesForMigration();
       final sTime = DateTime.now().microsecondsSinceEpoch;
       bool hasData = true;
       const int limitInBatch = 100;
       while (hasData) {
-        var localIDsToProcess =
+        final localIDsToProcess =
             await _fileUpdationDB.getLocalIDsForPotentialReUpload(
           limitInBatch,
           FileUpdationDB.missingLocation,
@@ -188,15 +188,15 @@ class LocalFileUpdateService {
     List<String> localIDsToProcess,
   ) async {
     _logger.info("files to process ${localIDsToProcess.length}");
-    var localIDsWithLocation = <String>[];
+    final localIDsWithLocation = <String>[];
     for (var localID in localIDsToProcess) {
       bool hasLocation = false;
       try {
-        var assetEntity = await AssetEntity.fromId(localID);
+        final assetEntity = await AssetEntity.fromId(localID);
         if (assetEntity == null) {
           continue;
         }
-        var latLng = await assetEntity.latlngAsync();
+        final latLng = await assetEntity.latlngAsync();
         if ((latLng.longitude ?? 0.0) != 0.0 ||
             (latLng.longitude ?? 0.0) != 0.0) {
           _logger.finest(
@@ -225,7 +225,7 @@ class LocalFileUpdateService {
     }
     final sTime = DateTime.now().microsecondsSinceEpoch;
     _logger.info('importing files without location info');
-    var fileLocalIDs = await _filesDB.getLocalFilesBackedUpWithoutLocation();
+    final fileLocalIDs = await _filesDB.getLocalFilesBackedUpWithoutLocation();
     await _fileUpdationDB.insertMultiple(
       fileLocalIDs,
       FileUpdationDB.missingLocation,

+ 2 - 2
lib/services/local_sync_service.dart

@@ -132,7 +132,7 @@ class LocalSyncService {
   }
 
   Future<bool> refreshDeviceFolderCountAndCover() async {
-    List<Tuple2<AssetPathEntity, String>> result =
+    final List<Tuple2<AssetPathEntity, String>> result =
         await getDeviceFolderWithCountAndCoverID();
     return await _db.updateDeviceCoverWithCount(
       result,
@@ -172,7 +172,7 @@ class LocalSyncService {
           .deletePathIDToLocalIDMapping(localUnSyncResult.deletePathToLocalIDs);
       hasAnyMappingChanged = true;
     }
-    bool hasUnsyncedFiles =
+    final bool hasUnsyncedFiles =
         localUnSyncResult.uniqueLocalFiles?.isNotEmpty ?? false;
     if (hasUnsyncedFiles) {
       await _db.insertMultiple(

+ 2 - 2
lib/services/remote_sync_service.dart

@@ -235,7 +235,7 @@ class RemoteSyncService {
     for (var devicePathCollection in devicePathCollections) {
       int deviceCollectionID = devicePathCollection.collectionID;
       if (deviceCollectionID != -1) {
-        var collectionByID =
+        final collectionByID =
             CollectionsService.instance.getCollectionByID(deviceCollectionID);
         if (collectionByID == null || collectionByID.isDeleted) {
           _logger.info(
@@ -246,7 +246,7 @@ class RemoteSyncService {
         }
       }
       if (deviceCollectionID == -1) {
-        var collection = await CollectionsService.instance
+        final collection = await CollectionsService.instance
             .getOrCreateForPath(devicePathCollection.name);
         await FilesDB.instance
             .updateDevicePathCollection(devicePathCollection.id, collection.id);

+ 1 - 1
lib/ui/backup_folder_selection_page.dart

@@ -172,7 +172,7 @@ class _BackupFolderSelectionPageState extends State<BackupFolderSelectionPage> {
                     onPressed: _selectedDevicePathIDs.isEmpty
                         ? null
                         : () async {
-                            Map<String, bool> syncStatus = {};
+                            final Map<String, bool> syncStatus = {};
                             for (String pathID in _allDevicePathIDs) {
                               syncStatus[pathID] =
                                   _selectedDevicePathIDs.contains(pathID);

+ 1 - 1
lib/utils/file_uploader_util.dart

@@ -103,7 +103,7 @@ Future<MediaUploadData> _getMediaUploadDataFromAssetFile(ente.File file) async {
       _logger.severe(errMsg);
       throw InvalidFileUploadState(errMsg);
     }
-    String livePhotoVideoHash =
+    final String livePhotoVideoHash =
         Sodium.bin2base64(await CryptoUtil.getHash(videoUrl));
     // imgHash:vidHash
     fileHash = '$fileHash$kLivePhotoHashSeparator$livePhotoVideoHash';