Switch to remoteDB

This commit is contained in:
Neeraj Gupta
2025-04-30 13:03:58 +05:30
parent 4a9b4520d2
commit 82497563c2
3 changed files with 38 additions and 48 deletions

View File

@@ -1422,23 +1422,6 @@ class FilesDB with SqlDbBase {
return files;
}
// For a given userID, return unique uploadedFileId for the given userID
Future<List<int>> 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 = <int>[];
for (final row in rows) {
result.add(row[columnUploadedFileID] as int);
}
return result;
}
Future<List<String>> 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<void> updateSizeForUploadIDs(
Map<int, int> uploadedFileIDToSize,
) async {
if (uploadedFileIDToSize.isEmpty) {
return;
}
final db = await instance.sqliteAsyncDB;
final parameterSets = <List<Object?>>[];
for (final uploadedFileID in uploadedFileIDToSize.keys) {
parameterSets.add([
uploadedFileIDToSize[uploadedFileID],
uploadedFileID,
]);
}
await db.executeBatch(
'''
UPDATE $filesTable
SET $columnFileSize = ?
WHERE $columnUploadedFileID = ?;
''',
parameterSets,
);
}
Future<List<EnteFile>> getAllFilesAfterDate({
required FileType fileType,
required DateTime beginDate,

View File

@@ -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<List<int>> fileIDsWithMissingSize(int userId) async {
final rows = await sqliteDB.getAll(
"SELECT id FROM files WHERE owner_id = ? AND size = -1",
[userId],
);
final result = <int>[];
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<void> updateSize(
Map<int, int> idToSize,
) async {
final parameterSets = <List<Object?>>[];
for (final id in idToSize.keys) {
parameterSets.add([idToSize[id], id]);
}
await sqliteDB.executeBatch(
"UPDATE files SET size = ? WHERE id = ?;",
parameterSets,
);
}
}

View File

@@ -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<bool> hasMigratedSizes() async {
try {
final List<int> 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<int, int> 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<EnteFile> uploadedFiles =
files.where((element) => element.uploadedFileID != null).toList();
files.where((element) => element.uploadedFileqID != null).toList();
final List<EnteFile> remoteFilesToUpdate = [];
final Map<int, Map<String, dynamic>> fileIDToUpdateMetadata = {};