diff --git a/mobile/lib/db/files_db.dart b/mobile/lib/db/files_db.dart index e76a38e884..885f747112 100644 --- a/mobile/lib/db/files_db.dart +++ b/mobile/lib/db/files_db.dart @@ -1422,23 +1422,6 @@ class FilesDB with SqlDbBase { return files; } - // For a given userID, return unique uploadedFileId for the given userID - Future> getUploadIDsWithMissingSize(int userId) async { - final db = await instance.sqliteAsyncDB; - final rows = await db.getAll( - ''' - SELECT DISTINCT $columnUploadedFileID FROM $filesTable - WHERE $columnOwnerID = ? AND $columnFileSize IS NULL - ''', - [userId], - ); - final result = []; - for (final row in rows) { - result.add(row[columnUploadedFileID] as int); - } - return result; - } - Future> getLocalFilesBackedUpWithoutLocation(int userId) async { final db = await instance.sqliteAsyncDB; final rows = await db.getAll( @@ -1458,34 +1441,6 @@ class FilesDB with SqlDbBase { return result; } - // updateSizeForUploadIDs takes a map of upploadedFileID and fileSize and - // update the fileSize for the given uploadedFileID - Future updateSizeForUploadIDs( - Map uploadedFileIDToSize, - ) async { - if (uploadedFileIDToSize.isEmpty) { - return; - } - final db = await instance.sqliteAsyncDB; - final parameterSets = >[]; - - for (final uploadedFileID in uploadedFileIDToSize.keys) { - parameterSets.add([ - uploadedFileIDToSize[uploadedFileID], - uploadedFileID, - ]); - } - - await db.executeBatch( - ''' - UPDATE $filesTable - SET $columnFileSize = ? - WHERE $columnUploadedFileID = ?; - ''', - parameterSets, - ); - } - Future> getAllFilesAfterDate({ required FileType fileType, required DateTime beginDate, diff --git a/mobile/lib/db/remote/table/files_table.dart b/mobile/lib/db/remote/table/files_table.dart new file mode 100644 index 0000000000..9969ae359c --- /dev/null +++ b/mobile/lib/db/remote/table/files_table.dart @@ -0,0 +1,31 @@ +import "package:photos/db/remote/db.dart"; + +extension FilesTable on RemoteDB { + // For a given userID, return unique uploadedFileId for the given userID + Future> fileIDsWithMissingSize(int userId) async { + final rows = await sqliteDB.getAll( + "SELECT id FROM files WHERE owner_id = ? AND size = -1", + [userId], + ); + final result = []; + for (final row in rows) { + result.add(row['id'] as int); + } + return result; + } + + // updateSizeForUploadIDs takes a map of upploadedFileID and fileSize and + // update the fileSize for the given uploadedFileID + Future updateSize( + Map idToSize, + ) async { + final parameterSets = >[]; + for (final id in idToSize.keys) { + parameterSets.add([idToSize[id], id]); + } + await sqliteDB.executeBatch( + "UPDATE files SET size = ? WHERE id = ?;", + parameterSets, + ); + } +} diff --git a/mobile/lib/services/files_service.dart b/mobile/lib/services/files_service.dart index d6f0994f30..a09fa0936c 100644 --- a/mobile/lib/services/files_service.dart +++ b/mobile/lib/services/files_service.dart @@ -7,12 +7,14 @@ import 'package:photos/core/configuration.dart'; import 'package:photos/core/network/network.dart'; import "package:photos/db/device_files_db.dart"; import 'package:photos/db/files_db.dart'; +import "package:photos/db/remote/table/files_table.dart"; import 'package:photos/extensions/list.dart'; import "package:photos/generated/l10n.dart"; import "package:photos/models/backup_status.dart"; import 'package:photos/models/file/file.dart'; import "package:photos/models/file_load_result.dart"; import "package:photos/models/metadata/file_magic.dart"; +import "package:photos/service_locator.dart"; import 'package:photos/services/file_magic_service.dart'; import "package:photos/services/ignored_files_service.dart"; import "package:photos/ui/components/action_sheet_widget.dart"; @@ -53,7 +55,7 @@ class FilesService { Future hasMigratedSizes() async { try { final List uploadIDsWithMissingSize = - await _filesDB.getUploadIDsWithMissingSize(_config.getUserID()!); + await remoteDB.fileIDsWithMissingSize(_config.getUserID()!); if (uploadIDsWithMissingSize.isEmpty) { return Future.value(true); } @@ -69,7 +71,9 @@ class FilesService { final batchedFiles = uploadIDsWithMissingSize.chunks(1000); for (final batch in batchedFiles) { final Map uploadIdToSize = await getFilesSizeFromInfo(batch); - await _filesDB.updateSizeForUploadIDs(uploadIdToSize); + if (uploadIdToSize.isNotEmpty) { + await remoteDB.updateSize(uploadIdToSize); + } } } @@ -132,7 +136,7 @@ class FilesService { BuildContext context, ) async { final List uploadedFiles = - files.where((element) => element.uploadedFileID != null).toList(); + files.where((element) => element.uploadedFileqID != null).toList(); final List remoteFilesToUpdate = []; final Map> fileIDToUpdateMetadata = {};