Use remoteDB to get files within duration
This commit is contained in:
@@ -730,39 +730,6 @@ class FilesDB with SqlDbBase {
|
||||
return files;
|
||||
}
|
||||
|
||||
Future<List<EnteFile>> getFilesCreatedWithinDurations(
|
||||
List<List<int>> durations,
|
||||
Set<int> ignoredCollectionIDs, {
|
||||
int? visibility,
|
||||
String order = 'ASC',
|
||||
}) async {
|
||||
if (durations.isEmpty) {
|
||||
return <EnteFile>[];
|
||||
}
|
||||
final db = await instance.sqliteAsyncDB;
|
||||
String whereClause = durations
|
||||
.map(
|
||||
(duration) =>
|
||||
"($columnCreationTime >= ${duration[0]} AND $columnCreationTime < ${duration[1]})",
|
||||
)
|
||||
.join(" OR ");
|
||||
|
||||
whereClause = "( $whereClause )";
|
||||
if (visibility != null) {
|
||||
whereClause += ' AND $columnMMdVisibility = $visibility';
|
||||
}
|
||||
final query =
|
||||
'SELECT * FROM $filesTable WHERE $whereClause ORDER BY $columnCreationTime $order';
|
||||
final results = await db.getAll(
|
||||
query,
|
||||
);
|
||||
final files = convertToFiles(results);
|
||||
return applyDBFilters(
|
||||
files,
|
||||
DBFilterOptions(ignoredCollectionIDs: ignoredCollectionIDs),
|
||||
);
|
||||
}
|
||||
|
||||
// Files which user added to a collection manually but they are not
|
||||
// uploaded yet or files belonging to a collection which is marked for backup
|
||||
Future<List<EnteFile>> getFilesPendingForUpload() async {
|
||||
|
||||
@@ -30,7 +30,7 @@ class RemoteDB with SqlDbBase {
|
||||
final db = SqliteDatabase(path: path);
|
||||
await migrate(db, RemoteDBMigration.migrationScripts, onForeignKey: true);
|
||||
_sqliteDB = db;
|
||||
devLog("RemoteDB init complete $path");
|
||||
debugPrint("RemoteDB init complete $path");
|
||||
}
|
||||
|
||||
SqliteDatabase get sqliteDB => _sqliteDB;
|
||||
|
||||
@@ -106,6 +106,24 @@ extension CollectionFiles on RemoteDB {
|
||||
return null;
|
||||
}
|
||||
|
||||
Future<List<CollectionFileEntry>> getFilesCreatedWithinDurations(
|
||||
List<List<int>> durations,
|
||||
Set<int> ignoredCollectionIDs, {
|
||||
String order = 'DESC',
|
||||
}) async {
|
||||
final List<CollectionFileEntry> result = [];
|
||||
for (final duration in durations) {
|
||||
final start = duration[0];
|
||||
final end = duration[1];
|
||||
final rows = await sqliteDB.getAll(
|
||||
"SELECT * FROM collection_files join files on files.id=collection_files.file_id WHERE files.creation_time BETWEEN ? AND ? AND collection_id NOT IN (${ignoredCollectionIDs.join(",")}) ORDER BY creation_time $order",
|
||||
[start, end],
|
||||
);
|
||||
result.addAll(rows.map((row) => CollectionFileEntry.fromMap(row)));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Future<void> deleteFiles(List<int> fileIDs) async {
|
||||
if (fileIDs.isEmpty) return;
|
||||
final stopwatch = Stopwatch()..start();
|
||||
|
||||
@@ -20,6 +20,7 @@ import "package:photos/models/memories/people_memory.dart";
|
||||
import "package:photos/models/memories/smart_memory.dart";
|
||||
import "package:photos/models/memories/smart_memory_constants.dart";
|
||||
import "package:photos/service_locator.dart";
|
||||
import "package:photos/services/collections_service.dart";
|
||||
import "package:photos/services/language_service.dart";
|
||||
import "package:photos/services/machine_learning/face_ml/person/person_service.dart";
|
||||
import "package:photos/services/notification_service.dart";
|
||||
@@ -224,7 +225,8 @@ class MemoriesCacheService {
|
||||
}
|
||||
final minimalFiles = await FilesDB.instance.getFilesFromIDs(
|
||||
minimalFileIDs.toList(),
|
||||
collectionsToIgnore: SearchService.instance.ignoreCollections(),
|
||||
collectionsToIgnore:
|
||||
CollectionsService.instance.getHiddenCollectionIds(),
|
||||
);
|
||||
final minimalFileIdsToFile = <int, EnteFile>{};
|
||||
for (final file in minimalFiles) {
|
||||
|
||||
@@ -91,4 +91,25 @@ class RemoteCache {
|
||||
}
|
||||
return EnteFile.fromRemoteAsset(asset, cf);
|
||||
}
|
||||
|
||||
Future<List<EnteFile>> getFilesCreatedWithinDurations(
|
||||
List<List<int>> durations,
|
||||
Set<int> ignoredCollectionIDs, {
|
||||
String order = 'DESC',
|
||||
}) async {
|
||||
final collectionFileEntries = await remoteDB.getFilesCreatedWithinDurations(
|
||||
durations,
|
||||
ignoredCollectionIDs,
|
||||
order: order,
|
||||
);
|
||||
final _ = isLoaded ?? await _load();
|
||||
final List<EnteFile> files = [];
|
||||
for (final entry in collectionFileEntries) {
|
||||
final asset = remoteAssets[entry.fileID];
|
||||
if (asset != null) {
|
||||
files.add(EnteFile.fromRemoteAsset(asset, entry));
|
||||
}
|
||||
}
|
||||
return files;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -309,7 +309,7 @@ class SearchService {
|
||||
final List<GenericSearchResult> searchResults = [];
|
||||
for (var month in _getMatchingMonths(context, query)) {
|
||||
final matchedFiles =
|
||||
await FilesDB.instance.getFilesCreatedWithinDurations(
|
||||
await remoteCache.getFilesCreatedWithinDurations(
|
||||
_getDurationsOfMonthInEveryYear(month.monthNumber),
|
||||
ignoreCollections(),
|
||||
order: 'DESC',
|
||||
@@ -340,7 +340,7 @@ class SearchService {
|
||||
final months = getMonthData(context)..shuffle();
|
||||
for (MonthData month in months) {
|
||||
final matchedFiles =
|
||||
await FilesDB.instance.getFilesCreatedWithinDurations(
|
||||
await remoteCache.getFilesCreatedWithinDurations(
|
||||
_getDurationsOfMonthInEveryYear(month.monthNumber),
|
||||
ignoreCollections(),
|
||||
order: 'DESC',
|
||||
@@ -376,7 +376,7 @@ class SearchService {
|
||||
for (var holiday in holidays) {
|
||||
if (holiday.name.toLowerCase().contains(query.toLowerCase())) {
|
||||
final matchedFiles =
|
||||
await FilesDB.instance.getFilesCreatedWithinDurations(
|
||||
await remoteCache.getFilesCreatedWithinDurations(
|
||||
_getDurationsForCalendarDateInEveryYear(holiday.day, holiday.month),
|
||||
ignoreCollections(),
|
||||
order: 'DESC',
|
||||
@@ -408,7 +408,7 @@ class SearchService {
|
||||
final holidays = getHolidays(context)..shuffle();
|
||||
for (var holiday in holidays) {
|
||||
final matchedFiles =
|
||||
await FilesDB.instance.getFilesCreatedWithinDurations(
|
||||
await remoteCache.getFilesCreatedWithinDurations(
|
||||
_getDurationsForCalendarDateInEveryYear(holiday.day, holiday.month),
|
||||
ignoreCollections(),
|
||||
order: 'DESC',
|
||||
@@ -1164,7 +1164,7 @@ class SearchService {
|
||||
final int month = potentialDate.item2.monthNumber;
|
||||
final int? year = potentialDate.item3; // nullable
|
||||
final matchedFiles =
|
||||
await FilesDB.instance.getFilesCreatedWithinDurations(
|
||||
await remoteCache.getFilesCreatedWithinDurations(
|
||||
_getDurationsForCalendarDateInEveryYear(day, month, year: year),
|
||||
ignoreCollections(),
|
||||
order: 'DESC',
|
||||
@@ -1347,7 +1347,7 @@ class SearchService {
|
||||
endOfDay.microsecondsSinceEpoch,
|
||||
];
|
||||
|
||||
final matchedFiles = await FilesDB.instance.getFilesCreatedWithinDurations(
|
||||
final matchedFiles = await remoteCache.getFilesCreatedWithinDurations(
|
||||
[durationOfDay],
|
||||
ignoreCollections(),
|
||||
order: 'DESC',
|
||||
@@ -1564,7 +1564,7 @@ class SearchService {
|
||||
}
|
||||
|
||||
Future<List<EnteFile>> _getFilesInYear(List<int> durationOfYear) async {
|
||||
return await FilesDB.instance.getFilesCreatedWithinDurations(
|
||||
return await remoteCache.getFilesCreatedWithinDurations(
|
||||
[durationOfYear],
|
||||
ignoreCollections(),
|
||||
order: "DESC",
|
||||
|
||||
Reference in New Issue
Block a user