Explorar o código

IgnoredFile: minor refactoring & improved documentation

Neeraj Gupta %!s(int64=3) %!d(string=hai) anos
pai
achega
f5a74f220a

+ 1 - 1
lib/core/configuration.dart

@@ -9,7 +9,7 @@ import 'package:path_provider/path_provider.dart';
 import 'package:photos/core/event_bus.dart';
 import 'package:photos/core/event_bus.dart';
 import 'package:photos/db/collections_db.dart';
 import 'package:photos/db/collections_db.dart';
 import 'package:photos/db/files_db.dart';
 import 'package:photos/db/files_db.dart';
-import 'package:photos/db/ignore_files_db.dart';
+import 'package:photos/db/ignored_files_db.dart';
 import 'package:photos/db/memories_db.dart';
 import 'package:photos/db/memories_db.dart';
 import 'package:photos/db/public_keys_db.dart';
 import 'package:photos/db/public_keys_db.dart';
 import 'package:photos/db/trash_db.dart';
 import 'package:photos/db/trash_db.dart';

+ 13 - 20
lib/db/ignore_files_db.dart → lib/db/ignored_files_db.dart

@@ -5,19 +5,17 @@ import 'package:path_provider/path_provider.dart';
 import 'package:photos/models/ignored_file.dart';
 import 'package:photos/models/ignored_file.dart';
 import 'package:sqflite/sqflite.dart';
 import 'package:sqflite/sqflite.dart';
 
 
-// Keeps track of local fileIDs which should be not uploaded to ente without
-// user's intervention, even if they marked the folder for backup.
-// Common cases: when a user deletes a file just from ente on current device or
-// when they delete a file from web/another device, we should not automatically
-// upload the files.
+// Keeps track of localIDs which should be not uploaded to ente without
+// user's intervention.
+// Common use case:
+// when a user deletes a file just from ente on current or different device.
 class IgnoreFilesDB {
 class IgnoreFilesDB {
-  static final _databaseName = "ente.ignore_files.db";
+  static final _databaseName = "ente.ignored_files.db";
   static final _databaseVersion = 1;
   static final _databaseVersion = 1;
-  static final Logger _logger = Logger("IgnoreFilesDB");
+  static final Logger _logger = Logger("IgnoredFilesDB");
   static final tableName = 'ignored_files';
   static final tableName = 'ignored_files';
 
 
   static final columnLocalID = 'local_id';
   static final columnLocalID = 'local_id';
-  static final columnDeviceFolder = 'device_folder';
   static final columnTitle = 'title';
   static final columnTitle = 'title';
   static final columnReason = 'reason';
   static final columnReason = 'reason';
 
 
@@ -26,12 +24,10 @@ class IgnoreFilesDB {
         CREATE TABLE $tableName (
         CREATE TABLE $tableName (
           $columnLocalID TEXT NOT NULL,
           $columnLocalID TEXT NOT NULL,
           $columnTitle TEXT NOT NULL,
           $columnTitle TEXT NOT NULL,
-          $columnDeviceFolder TEXT,
           $columnReason TEXT DEFAULT $kIgnoreReasonTrash,
           $columnReason TEXT DEFAULT $kIgnoreReasonTrash,
-          UNIQUE($columnLocalID, $columnDeviceFolder, $columnDeviceFolder)
+          UNIQUE($columnLocalID, $columnTitle)
         );
         );
       CREATE INDEX IF NOT EXISTS local_id_index ON $tableName($columnLocalID);
       CREATE INDEX IF NOT EXISTS local_id_index ON $tableName($columnLocalID);
-      CREATE INDEX IF NOT EXISTS device_folder_index ON $tableName($columnDeviceFolder);
       ''');
       ''');
   }
   }
 
 
@@ -104,9 +100,10 @@ class IgnoreFilesDB {
   }
   }
 
 
   // return map of localID to set of titles associated with the given localIDs
   // return map of localID to set of titles associated with the given localIDs
-  // Note: localIDs can easily clash across devices for Android. The set of titles
-  // is to handle that case. In iOS, for selected permissions, we may not always
-  // get correct deviceFolder.
+  // Note: localIDs can easily clash across devices for Android, so we should
+  // always compare both localID & title in Android before ignoring the file for upload.
+  // iOS: localID is usually UUID and the title in localDB may be missing (before upload) as the
+  // photo manager library doesn't always fetch the title by default.
   Future<Map<String, Set<String>>> getIgnoredFiles() async {
   Future<Map<String, Set<String>>> getIgnoredFiles() async {
     final db = await instance.database;
     final db = await instance.database;
     final rows = await db.query(tableName);
     final rows = await db.query(tableName);
@@ -121,8 +118,7 @@ class IgnoreFilesDB {
   }
   }
 
 
   IgnoredFile _getIgnoredFileFromRow(Map<String, dynamic> row) {
   IgnoredFile _getIgnoredFileFromRow(Map<String, dynamic> row) {
-    return IgnoredFile(row[columnLocalID], row[columnDeviceFolder],
-        row[columnTitle], row[columnReason]);
+    return IgnoredFile(row[columnLocalID], row[columnTitle], row[columnReason]);
   }
   }
 
 
   Map<String, dynamic> _getRowForIgnoredFile(IgnoredFile ignoredFile) {
   Map<String, dynamic> _getRowForIgnoredFile(IgnoredFile ignoredFile) {
@@ -131,10 +127,7 @@ class IgnoreFilesDB {
     final row = <String, dynamic>{};
     final row = <String, dynamic>{};
     row[columnLocalID] = ignoredFile.localID;
     row[columnLocalID] = ignoredFile.localID;
     row[columnTitle] = ignoredFile.title;
     row[columnTitle] = ignoredFile.title;
-    row[columnDeviceFolder] = ignoredFile.deviceFolder;
-    if (ignoredFile.reason != null && ignoredFile.reason != "") {
-      row[columnReason] = ignoredFile.reason;
-    }
+    row[columnReason] = ignoredFile.reason;
     return row;
     return row;
   }
   }
 }
 }

+ 3 - 4
lib/models/ignored_file.dart

@@ -2,13 +2,13 @@ import 'package:photos/models/trash_file.dart';
 
 
 const kIgnoreReasonTrash = "trash";
 const kIgnoreReasonTrash = "trash";
 const kIgnoreReasonInvalidFile = "invalidFile";
 const kIgnoreReasonInvalidFile = "invalidFile";
+
 class IgnoredFile {
 class IgnoredFile {
   final String localID;
   final String localID;
-  final String deviceFolder;
   final String title;
   final String title;
   String reason;
   String reason;
 
 
-  IgnoredFile(this.localID, this.deviceFolder, this.title, this.reason);
+  IgnoredFile(this.localID, this.title, this.reason);
 
 
   factory IgnoredFile.fromTrashItem(TrashFile trashFile) {
   factory IgnoredFile.fromTrashItem(TrashFile trashFile) {
     if (trashFile == null) return null;
     if (trashFile == null) return null;
@@ -19,7 +19,6 @@ class IgnoredFile {
       return null;
       return null;
     }
     }
 
 
-    return IgnoredFile(trashFile.localID, trashFile.deviceFolder,
-        trashFile.title, kIgnoreReasonTrash);
+    return IgnoredFile(trashFile.localID, trashFile.title, kIgnoreReasonTrash);
   }
   }
 }
 }

+ 1 - 1
lib/services/remote_sync_service.dart

@@ -7,7 +7,7 @@ import 'package:photos/core/configuration.dart';
 import 'package:photos/core/errors.dart';
 import 'package:photos/core/errors.dart';
 import 'package:photos/core/event_bus.dart';
 import 'package:photos/core/event_bus.dart';
 import 'package:photos/db/files_db.dart';
 import 'package:photos/db/files_db.dart';
-import 'package:photos/db/ignore_files_db.dart';
+import 'package:photos/db/ignored_files_db.dart';
 import 'package:photos/events/collection_updated_event.dart';
 import 'package:photos/events/collection_updated_event.dart';
 import 'package:photos/events/files_updated_event.dart';
 import 'package:photos/events/files_updated_event.dart';
 import 'package:photos/events/local_photos_updated_event.dart';
 import 'package:photos/events/local_photos_updated_event.dart';

+ 1 - 1
lib/services/trash_sync_service.dart

@@ -3,7 +3,7 @@ import 'package:logging/logging.dart';
 import 'package:photos/core/configuration.dart';
 import 'package:photos/core/configuration.dart';
 import 'package:photos/core/network.dart';
 import 'package:photos/core/network.dart';
 import 'package:photos/db/files_db.dart';
 import 'package:photos/db/files_db.dart';
-import 'package:photos/db/ignore_files_db.dart';
+import 'package:photos/db/ignored_files_db.dart';
 import 'package:photos/db/trash_db.dart';
 import 'package:photos/db/trash_db.dart';
 import 'package:photos/models/ignored_file.dart';
 import 'package:photos/models/ignored_file.dart';
 import 'package:photos/models/trash_file.dart';
 import 'package:photos/models/trash_file.dart';