Switch to remote db 1/51
This commit is contained in:
@@ -1282,30 +1282,6 @@ class FilesDB with SqlDbBase {
|
||||
return result;
|
||||
}
|
||||
|
||||
// getCollectionLatestFileTime returns map of collectionID to the max
|
||||
// creationTime of the files in the collection.
|
||||
Future<Map<int, int>> getCollectionIDToMaxCreationTime() async {
|
||||
final enteWatch = EnteWatch("getCollectionIDToMaxCreationTime")..start();
|
||||
final db = await instance.sqliteAsyncDB;
|
||||
final rows = await db.getAll(
|
||||
'''
|
||||
SELECT $columnCollectionID, MAX($columnCreationTime) AS max_creation_time
|
||||
FROM $filesTable
|
||||
WHERE
|
||||
($columnCollectionID IS NOT NULL AND $columnCollectionID IS NOT -1
|
||||
AND $columnUploadedFileID IS NOT NULL AND $columnUploadedFileID IS
|
||||
NOT -1)
|
||||
GROUP BY $columnCollectionID;
|
||||
''',
|
||||
);
|
||||
final result = <int, int>{};
|
||||
for (final row in rows) {
|
||||
result[row[columnCollectionID] as int] = row['max_creation_time'] as int;
|
||||
}
|
||||
enteWatch.log("query done");
|
||||
return result;
|
||||
}
|
||||
|
||||
Future<Map<int, int>> getFileIDToCreationTime() async {
|
||||
final db = await instance.sqliteAsyncDB;
|
||||
final rows = await db.getAll(
|
||||
@@ -1406,22 +1382,6 @@ class FilesDB with SqlDbBase {
|
||||
return result;
|
||||
}
|
||||
|
||||
List<EnteFile> convertToFilesForIsolate(Map args) {
|
||||
final List<EnteFile> files = [];
|
||||
for (final result in args["result"]) {
|
||||
files.add(_getFileFromRow(result));
|
||||
}
|
||||
return files;
|
||||
}
|
||||
|
||||
List<EnteFile> convertToFiles(List<Map<String, dynamic>> results) {
|
||||
final List<EnteFile> files = [];
|
||||
for (final result in results) {
|
||||
files.add(_getFileFromRow(result));
|
||||
}
|
||||
return files;
|
||||
}
|
||||
|
||||
Future<List<String>> getLocalFilesBackedUpWithoutLocation(int userId) async {
|
||||
final db = await instance.sqliteAsyncDB;
|
||||
final rows = await db.getAll(
|
||||
@@ -1562,6 +1522,22 @@ class FilesDB with SqlDbBase {
|
||||
};
|
||||
}
|
||||
|
||||
List<EnteFile> convertToFilesForIsolate(Map args) {
|
||||
final List<EnteFile> files = [];
|
||||
for (final result in args["result"]) {
|
||||
files.add(_getFileFromRow(result));
|
||||
}
|
||||
return files;
|
||||
}
|
||||
|
||||
List<EnteFile> convertToFiles(List<Map<String, dynamic>> results) {
|
||||
final List<EnteFile> files = [];
|
||||
for (final result in results) {
|
||||
files.add(_getFileFromRow(result));
|
||||
}
|
||||
return files;
|
||||
}
|
||||
|
||||
List<Object?> _getParameterSetForFile(
|
||||
EnteFile file, {
|
||||
bool omitCollectionId = false,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import "package:photos/db/remote/db.dart";
|
||||
import "package:photos/db/remote/schema.dart";
|
||||
import "package:photos/extensions/stop_watch.dart";
|
||||
import "package:photos/models/file/remote/file_entry.dart";
|
||||
|
||||
extension CollectionFiles on RemoteDB {
|
||||
@@ -90,4 +91,20 @@ extension CollectionFiles on RemoteDB {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Future<Map<int, int>> getCollectionIDToMaxCreationTime() async {
|
||||
final enteWatch = EnteWatch("getCollectionIDToMaxCreationTime")..start();
|
||||
final rows = await sqliteDB.getAll(
|
||||
'''SELECT collection_id, MAX(creation_time) as max_creation_time FROM collection_files join files on
|
||||
collection_files.file_id=files.id GROUP BY collection_id''',
|
||||
);
|
||||
final Map<int, int> result = {};
|
||||
for (var row in rows) {
|
||||
final collectionId = row["collection_id"] as int;
|
||||
final maxCreationTime = row["max_creation_time"] as int;
|
||||
result[collectionId] = maxCreationTime;
|
||||
}
|
||||
enteWatch.log("query done");
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -308,7 +308,7 @@ class CollectionsService {
|
||||
|
||||
Future<Map<int, int>> getCollectionIDToNewestFileTime() {
|
||||
_collectionIDToNewestFileTime ??=
|
||||
_filesDB.getCollectionIDToMaxCreationTime();
|
||||
remoteDB.getCollectionIDToMaxCreationTime();
|
||||
return _collectionIDToNewestFileTime!;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:photos/core/event_bus.dart';
|
||||
import "package:photos/db/files_db.dart";
|
||||
import "package:photos/db/remote/table/collection_files.dart";
|
||||
import 'package:photos/events/collection_updated_event.dart';
|
||||
import "package:photos/generated/l10n.dart";
|
||||
import 'package:photos/models/collection/collection.dart';
|
||||
import 'package:photos/models/file/file.dart';
|
||||
import "package:photos/service_locator.dart";
|
||||
import 'package:photos/services/collections_service.dart';
|
||||
import "package:photos/services/sync/remote_sync_service.dart";
|
||||
import 'package:photos/ui/components/action_sheet_widget.dart';
|
||||
@@ -120,8 +122,7 @@ class _DeleteEmptyAlbumsState extends State<DeleteEmptyAlbums> {
|
||||
|
||||
Future<void> _deleteEmptyAlbums() async {
|
||||
final collections = CollectionsService.instance.getCollectionsForUI();
|
||||
final idToFileTimeStamp =
|
||||
await FilesDB.instance.getCollectionIDToMaxCreationTime();
|
||||
final idToFileTimeStamp = await remoteDB.getCollectionIDToMaxCreationTime();
|
||||
|
||||
// remove collections which are not empty or can't be deleted
|
||||
collections.removeWhere(
|
||||
|
||||
Reference in New Issue
Block a user