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

View file

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

View file

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

View file

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