mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-01-22 08:46:18 +01:00
DB api to support filtering locations by time range
This commit is contained in:
parent
4bb825a7dc
commit
739b23b8ba
5 changed files with 21 additions and 7 deletions
|
@ -8,6 +8,7 @@ import 'package:nc_photos/entity/image_location/repo.dart';
|
|||
import 'package:nc_photos/remote_storage_util.dart' as remote_storage_util;
|
||||
import 'package:np_async/np_async.dart';
|
||||
import 'package:np_codegen/np_codegen.dart';
|
||||
import 'package:np_datetime/np_datetime.dart';
|
||||
import 'package:np_db/np_db.dart';
|
||||
|
||||
part 'data_source.g.dart';
|
||||
|
@ -17,10 +18,12 @@ class ImageLocationNpDbDataSource implements ImageLocationDataSource {
|
|||
const ImageLocationNpDbDataSource(this.db);
|
||||
|
||||
@override
|
||||
Future<List<ImageLatLng>> getLocations(Account account) async {
|
||||
_log.info("[getLocations]");
|
||||
Future<List<ImageLatLng>> getLocations(
|
||||
Account account, TimeRange timeRange) async {
|
||||
_log.info("[getLocations] timeRange: $timeRange");
|
||||
final results = await db.getImageLatLngWithFileIds(
|
||||
account: account.toDb(),
|
||||
timeRange: timeRange,
|
||||
includeRelativeRoots: account.roots
|
||||
.map((e) => File(path: file_util.unstripPath(account, e))
|
||||
.strippedPathWithEmpty)
|
||||
|
|
|
@ -2,6 +2,7 @@ import 'package:equatable/equatable.dart';
|
|||
import 'package:logging/logging.dart';
|
||||
import 'package:nc_photos/account.dart';
|
||||
import 'package:np_codegen/np_codegen.dart';
|
||||
import 'package:np_datetime/np_datetime.dart';
|
||||
|
||||
part 'repo.g.dart';
|
||||
|
||||
|
@ -28,7 +29,7 @@ abstract class ImageLocationRepo {
|
|||
/// Query all locations with the corresponding file ids
|
||||
///
|
||||
/// Returned data are sorted by the file date time in descending order
|
||||
Future<List<ImageLatLng>> getLocations(Account account);
|
||||
Future<List<ImageLatLng>> getLocations(Account account, TimeRange timeRange);
|
||||
}
|
||||
|
||||
@npLog
|
||||
|
@ -36,8 +37,9 @@ class BasicImageLocationRepo implements ImageLocationRepo {
|
|||
const BasicImageLocationRepo(this.dataSrc);
|
||||
|
||||
@override
|
||||
Future<List<ImageLatLng>> getLocations(Account account) =>
|
||||
dataSrc.getLocations(account);
|
||||
Future<List<ImageLatLng>> getLocations(
|
||||
Account account, TimeRange timeRange) =>
|
||||
dataSrc.getLocations(account, timeRange);
|
||||
|
||||
final ImageLocationDataSource dataSrc;
|
||||
}
|
||||
|
@ -46,5 +48,5 @@ abstract class ImageLocationDataSource {
|
|||
/// Query all locations with the corresponding file ids
|
||||
///
|
||||
/// Returned data are sorted by the file date time in descending order
|
||||
Future<List<ImageLatLng>> getLocations(Account account);
|
||||
Future<List<ImageLatLng>> getLocations(Account account, TimeRange timeRange);
|
||||
}
|
||||
|
|
|
@ -435,6 +435,7 @@ abstract class NpDb {
|
|||
/// Return the latitude, longitude and the file id of all files
|
||||
Future<List<DbImageLatLng>> getImageLatLngWithFileIds({
|
||||
required DbAccount account,
|
||||
TimeRange? timeRange,
|
||||
List<String>? includeRelativeRoots,
|
||||
List<String>? excludeRelativeRoots,
|
||||
List<String>? mimes,
|
||||
|
|
|
@ -31,12 +31,13 @@ class ImageLatLng {
|
|||
extension SqliteDbImageLocationExtension on SqliteDb {
|
||||
Future<List<ImageLatLng>> queryImageLatLngWithFileIds({
|
||||
required ByAccount account,
|
||||
TimeRange? timeRange,
|
||||
List<String>? includeRelativeRoots,
|
||||
List<String>? includeRelativeDirs,
|
||||
List<String>? excludeRelativeRoots,
|
||||
List<String>? mimes,
|
||||
}) async {
|
||||
_log.info("[queryImageLatLngWithFileIds]");
|
||||
_log.info("[queryImageLatLngWithFileIds] timeRange: $timeRange");
|
||||
final query = _queryFiles().let((q) {
|
||||
q
|
||||
..setQueryMode(
|
||||
|
@ -73,6 +74,11 @@ extension SqliteDbImageLocationExtension on SqliteDb {
|
|||
} else {
|
||||
query.where(files.isCollection.isNotValue(true));
|
||||
}
|
||||
if (timeRange != null) {
|
||||
accountFiles.bestDateTime
|
||||
.isBetweenTimeRange(timeRange)
|
||||
?.let((e) => query.where(e));
|
||||
}
|
||||
query
|
||||
..where(imageLocations.latitude.isNotNull() &
|
||||
imageLocations.longitude.isNotNull())
|
||||
|
|
|
@ -578,6 +578,7 @@ class NpDbSqlite implements NpDb {
|
|||
@override
|
||||
Future<List<DbImageLatLng>> getImageLatLngWithFileIds({
|
||||
required DbAccount account,
|
||||
TimeRange? timeRange,
|
||||
List<String>? includeRelativeRoots,
|
||||
List<String>? excludeRelativeRoots,
|
||||
List<String>? mimes,
|
||||
|
@ -585,6 +586,7 @@ class NpDbSqlite implements NpDb {
|
|||
final sqlObjs = await _db.use((db) async {
|
||||
return await db.queryImageLatLngWithFileIds(
|
||||
account: ByAccount.db(account),
|
||||
timeRange: timeRange,
|
||||
includeRelativeRoots: includeRelativeRoots,
|
||||
excludeRelativeRoots: excludeRelativeRoots,
|
||||
mimes: mimes,
|
||||
|
|
Loading…
Reference in a new issue