Support querying getFileDescriptors with time range filter and offset

This commit is contained in:
Ming Ming 2024-04-10 01:15:07 +08:00
parent 0bf19c9203
commit 2d5e470508
4 changed files with 34 additions and 8 deletions

View file

@ -21,6 +21,7 @@ import 'package:nc_photos/entity/tag.dart';
import 'package:nc_photos/exception_event.dart'; import 'package:nc_photos/exception_event.dart';
import 'package:np_async/np_async.dart'; import 'package:np_async/np_async.dart';
import 'package:np_common/or_null.dart'; import 'package:np_common/or_null.dart';
import 'package:np_datetime/np_datetime.dart';
import 'package:np_string/np_string.dart'; import 'package:np_string/np_string.dart';
import 'package:path/path.dart' as path_lib; import 'package:path/path.dart' as path_lib;
@ -307,7 +308,12 @@ class MockFileMemoryRepo extends FileRepo {
class MockFileDataSource2 implements FileDataSource2 { class MockFileDataSource2 implements FileDataSource2 {
@override @override
Stream<List<FileDescriptor>> getFileDescriptors( Stream<List<FileDescriptor>> getFileDescriptors(
Account account, String shareDirPath) { Account account,
String shareDirPath, {
TimeRange? timeRange,
int? offset,
int? limit,
}) {
throw UnimplementedError(); throw UnimplementedError();
} }
@ -337,7 +343,12 @@ class MockFileMemoryDataSource2 extends MockFileDataSource2 {
@override @override
Stream<List<FileDescriptor>> getFileDescriptors( Stream<List<FileDescriptor>> getFileDescriptors(
Account account, String shareDirPath) async* { Account account,
String shareDirPath, {
TimeRange? timeRange,
int? offset,
int? limit,
}) async* {
yield files.where((f) { yield files.where((f) {
if (account.roots.any((r) => file_util.isOrUnderDirPath( if (account.roots.any((r) => file_util.isOrUnderDirPath(
f.fdPath, file_util.unstripPath(account, r)))) { f.fdPath, file_util.unstripPath(account, r)))) {

View file

@ -347,6 +347,8 @@ abstract class NpDb {
String? location, String? location,
bool? isFavorite, bool? isFavorite,
List<String>? mimes, List<String>? mimes,
TimeRange? timeRange,
int? offset,
int? limit, int? limit,
}); });

View file

@ -402,6 +402,8 @@ extension SqliteDbFileExtension on SqliteDb {
String? location, String? location,
bool? isFavorite, bool? isFavorite,
List<String>? mimes, List<String>? mimes,
TimeRange? timeRange,
int? offset,
int? limit, int? limit,
}) async { }) async {
_log.info( _log.info(
@ -414,6 +416,8 @@ extension SqliteDbFileExtension on SqliteDb {
"location: $location, " "location: $location, "
"isFavorite: $isFavorite, " "isFavorite: $isFavorite, "
"mimes: $mimes, " "mimes: $mimes, "
"timeRange: $timeRange, "
"offset: $offset, "
"limit: $limit", "limit: $limit",
); );
@ -457,13 +461,13 @@ extension SqliteDbFileExtension on SqliteDb {
if (dirIds != null) { if (dirIds != null) {
for (final i in dirIds) { for (final i in dirIds) {
q.byOrDirRowId(i); q.byOrDirRowId(i);
} }
} }
} }
} else { } else {
if (dirIds != null) { if (dirIds != null) {
for (final i in dirIds) { for (final i in dirIds) {
q.byOrDirRowId(i); q.byOrDirRowId(i);
} }
} }
} }
@ -490,7 +494,12 @@ extension SqliteDbFileExtension on SqliteDb {
} }
query.orderBy([OrderingTerm.desc(accountFiles.bestDateTime)]); query.orderBy([OrderingTerm.desc(accountFiles.bestDateTime)]);
if (limit != null) { if (limit != null) {
query.limit(limit); query.limit(limit, offset: offset);
}
if (timeRange != null) {
accountFiles.bestDateTime
.isBetweenTimeRange(timeRange)
?.let((e) => query.where(e));
} }
return query return query
.map((r) => FileDescriptor( .map((r) => FileDescriptor(

View file

@ -444,6 +444,8 @@ class NpDbSqlite implements NpDb {
String? location, String? location,
bool? isFavorite, bool? isFavorite,
List<String>? mimes, List<String>? mimes,
TimeRange? timeRange,
int? offset,
int? limit, int? limit,
}) async { }) async {
final sqlObjs = await _db.use((db) async { final sqlObjs = await _db.use((db) async {
@ -457,6 +459,8 @@ class NpDbSqlite implements NpDb {
location: location, location: location,
isFavorite: isFavorite, isFavorite: isFavorite,
mimes: mimes, mimes: mimes,
timeRange: timeRange,
offset: offset,
limit: limit, limit: limit,
); );
}); });