Use remoteDB

This commit is contained in:
Neeraj Gupta
2025-04-30 14:10:04 +05:30
parent beeaee4fd9
commit 26222ec836
7 changed files with 47 additions and 35 deletions

View File

@@ -516,6 +516,7 @@ class FilesDB with SqlDbBase {
);
}
// blocked upload queue
Future<int> insertAndGetId(EnteFile file) async {
_logger.info("Inserting $file");
final db = await instance.sqliteAsyncDB;
@@ -532,6 +533,7 @@ class FilesDB with SqlDbBase {
});
}
// upload queue
Future<EnteFile?> getFile(int generatedID) async {
final db = await instance.sqliteAsyncDB;
final results = await db.getAll(
@@ -544,18 +546,6 @@ class FilesDB with SqlDbBase {
return convertToFiles(results)[0];
}
Future<EnteFile?> getAnyUploadedFile(int uploadedID) async {
final db = await instance.sqliteAsyncDB;
final results = await db.getAll(
'SELECT * FROM $filesTable WHERE $columnUploadedFileID = ?',
[uploadedID],
);
if (results.isEmpty) {
return null;
}
return convertToFiles(results)[0];
}
Future<(Set<int>, Map<String, int>)> getUploadAndHash(
int collectionID,
) async {
@@ -1179,19 +1169,6 @@ class FilesDB with SqlDbBase {
return convertToFiles(results);
}
Future<void> deleteUnSyncedLocalFiles(List<String> localIDs) async {
final inParam = localIDs.map((id) => "'$id'").join(',');
final db = await instance.sqliteAsyncDB;
unawaited(
db.execute(
'''
DELETE FROM $filesTable
WHERE ($columnUploadedFileID is NULL OR $columnUploadedFileID = -1 ) AND $columnLocalID IN ($inParam)
''',
),
);
}
Future<int> deleteFilesFromCollection(
int collectionID,
List<int> uploadedFileIDs,
@@ -1248,6 +1225,7 @@ class FilesDB with SqlDbBase {
);
}
// todo:rewrite (upload related)
Future<List<EnteFile>> getPendingUploadForCollection(int collectionID) async {
final db = await instance.sqliteAsyncDB;
final results = await db.getAll(
@@ -1258,6 +1236,7 @@ class FilesDB with SqlDbBase {
return convertToFiles(results);
}
// todo:rewrite (upload related)
Future<Set<String>> getLocalIDsPresentInEntries(
List<EnteFile> existingFiles,
int collectionID,
@@ -1299,6 +1278,7 @@ class FilesDB with SqlDbBase {
return result;
}
// todo:rewrite (upload related)
Future<void> markForReUploadIfLocationMissing(List<String> localIDs) async {
if (localIDs.isEmpty) {
return;

View File

@@ -92,6 +92,19 @@ extension CollectionFiles on RemoteDB {
return null;
}
Future<CollectionFileEntry?> getAnyCollectionEntry(
int fileID,
) async {
final row = await sqliteDB.getAll(
"SELECT * FROM collection_files WHERE file_id = ? limit 1",
[fileID],
);
if (row.isNotEmpty) {
return CollectionFileEntry.fromMap(row.first);
}
return null;
}
Future<Map<int, int>> getCollectionIDToMaxCreationTime() async {
final enteWatch = EnteWatch("getCollectionIDToMaxCreationTime")..start();
final rows = await sqliteDB.getAll(

View File

@@ -1768,13 +1768,15 @@ class CollectionsService {
// Remove imported local files which are imported but not uploaded.
// This handles the case where local file was trashed -> imported again
// but not uploaded automatically as it was trashed.
final localIDs = batch
.where((e) => e.localID != null)
.map((e) => e.localID!)
.toSet()
.toList();
if (localIDs.isNotEmpty) {
await _filesDB.deleteUnSyncedLocalFiles(localIDs);
// todo:(rewrite) remove enteries from upload_mapping table
// if we decide to use it for book keeping
}
// Force reload home gallery to pull in the restored files
Bus.instance.fire(ForceReloadHomeGalleryEvent("restoredFromTrash"));

View File

@@ -10,6 +10,7 @@ import "package:photos/db/remote/table/collection_files.dart";
import 'package:photos/events/collection_updated_event.dart';
import "package:photos/events/favorites_service_init_complete_event.dart";
import 'package:photos/events/files_updated_event.dart';
import "package:photos/log/devlog.dart";
import 'package:photos/models/api/collection/create_request.dart';
import 'package:photos/models/collection/collection.dart';
import 'package:photos/models/file/file.dart';
@@ -85,7 +86,7 @@ class FavoritesService {
if (file.collectionID != null &&
_cachedFavoritesCollectionID != null &&
file.collectionID == _cachedFavoritesCollectionID) {
debugPrint("File ${file.uploadedFileID} is part of favorite collection");
devLog("File ${file.uploadedFileID} is part of favorite collection");
return true;
}
if (checkOnlyAlbum) {

View File

@@ -1,5 +1,5 @@
import "package:photos/db/remote/table/collection_files.dart";
import "package:photos/db/remote/schema.dart";
import "package:photos/db/remote/table/collection_files.dart";
import "package:photos/models/collection/collection.dart";
import "package:photos/models/file/file.dart";
import "package:photos/models/file/remote/asset.dart";
@@ -54,10 +54,10 @@ class RemoteCache {
c.pubMagicMetadata.coverID,
sortInAsc: c.pubMagicMetadata.asc ?? false,
);
final _ = isLoaded ?? await _load();
if (cf == null) {
return null;
}
final _ = isLoaded ?? await _load();
final asset = remoteAssets[cf.fileID];
if (asset == null) {
return null;
@@ -67,10 +67,24 @@ class RemoteCache {
Future<EnteFile?> getCollectionFile(int collectionID, int fileID) async {
final cf = await remoteDB.getCollectionFileEntry(collectionID, fileID);
final _ = isLoaded ?? await _load();
if (cf == null) {
return null;
}
final _ = isLoaded ?? await _load();
final asset = remoteAssets[cf.fileID];
if (asset == null) {
return null;
}
return EnteFile.fromRemoteAsset(asset, cf);
}
Future<EnteFile?> getAnyCollectionFile(int fileID) async {
final cf = await remoteDB.getAnyCollectionEntry(fileID);
if (cf == null) {
return null;
}
final _ = isLoaded ?? await _load();
final asset = remoteAssets[cf.fileID];
if (asset == null) {
return null;

View File

@@ -7,6 +7,7 @@ import "package:photos/db/ml/db.dart";
import 'package:photos/models/file/file.dart';
import "package:photos/models/ml/face/face.dart";
import "package:photos/models/ml/face/person.dart";
import "package:photos/service_locator.dart";
import "package:photos/services/machine_learning/face_ml/person/person_service.dart";
import "package:photos/services/machine_learning/ml_result.dart";
import "package:photos/services/search_service.dart";
@@ -137,7 +138,7 @@ class _PersonFaceWidgetState extends State<PersonFaceWidget> {
});
if (fileForFaceCrop.uploadedFileID != recentFileID) {
fileForFaceCrop =
await FilesDB.instance.getAnyUploadedFile(recentFileID);
await remoteCache.getAnyCollectionFile(recentFileID);
if (fileForFaceCrop == null) return null;
}
}
@@ -155,8 +156,7 @@ class _PersonFaceWidgetState extends State<PersonFaceWidget> {
return null;
}
if (face.fileID != fileForFaceCrop.uploadedFileID!) {
fileForFaceCrop =
await FilesDB.instance.getAnyUploadedFile(face.fileID);
fileForFaceCrop = await remoteCache.getAnyCollectionFile(face.fileID);
if (fileForFaceCrop == null) return null;
}
final cropMap = await getCachedFaceCrops(

View File

@@ -10,6 +10,7 @@ import "package:photos/models/file/file.dart";
import "package:photos/models/file/file_type.dart";
import "package:photos/models/ml/face/box.dart";
import "package:photos/models/ml/face/face.dart";
import "package:photos/service_locator.dart";
import "package:photos/services/machine_learning/face_thumbnail_generator.dart";
import "package:photos/utils/file_util.dart";
import "package:photos/utils/thumbnail_util.dart";
@@ -147,7 +148,8 @@ Future<Uint8List?> precomputeClusterFaceCrop(
required bool useFullFile,
}) async {
try {
final w = (kDebugMode ? EnteWatch('precomputeClusterFaceCrop') : null)?..start();
final w = (kDebugMode ? EnteWatch('precomputeClusterFaceCrop') : null)
?..start();
final Face? face = await MLDataDB.instance.getCoverFaceForPerson(
recentFileID: file.uploadedFileID!,
clusterID: clusterID,
@@ -161,7 +163,7 @@ Future<Uint8List?> precomputeClusterFaceCrop(
}
EnteFile? fileForFaceCrop = file;
if (face.fileID != file.uploadedFileID!) {
fileForFaceCrop = await FilesDB.instance.getAnyUploadedFile(face.fileID);
fileForFaceCrop = await remoteCache.getAnyCollectionFile(face.fileID);
w?.log('getAnyUploadedFile');
}
if (fileForFaceCrop == null) {