|
|
|
|
@ -1,6 +1,8 @@
|
|
|
|
|
import 'package:drift/drift.dart';
|
|
|
|
|
import 'package:immich_mobile/domain/models/asset/base_asset.model.dart';
|
|
|
|
|
import 'package:immich_mobile/domain/models/person.model.dart';
|
|
|
|
|
import 'package:immich_mobile/infrastructure/entities/person.entity.drift.dart';
|
|
|
|
|
import 'package:immich_mobile/infrastructure/entities/remote_asset.entity.drift.dart';
|
|
|
|
|
import 'package:immich_mobile/infrastructure/repositories/db.repository.dart';
|
|
|
|
|
|
|
|
|
|
class DriftPeopleRepository extends DriftDatabaseRepository {
|
|
|
|
|
@ -21,10 +23,25 @@ class DriftPeopleRepository extends DriftDatabaseRepository {
|
|
|
|
|
Future<List<DriftPerson>> getAllPeople() async {
|
|
|
|
|
final query =
|
|
|
|
|
_db.select(_db.personEntity).join([
|
|
|
|
|
leftOuterJoin(_db.assetFaceEntity, _db.assetFaceEntity.personId.equalsExp(_db.personEntity.id)),
|
|
|
|
|
innerJoin(_db.assetFaceEntity, _db.assetFaceEntity.personId.equalsExp(_db.personEntity.id)),
|
|
|
|
|
innerJoin(
|
|
|
|
|
_db.remoteAssetEntity,
|
|
|
|
|
_db.remoteAssetEntity.id.equalsExp(_db.assetFaceEntity.assetId) &
|
|
|
|
|
_db.remoteAssetEntity.visibility.equals(
|
|
|
|
|
$RemoteAssetEntityTable.$convertervisibility.toSql(AssetVisibility.timeline),
|
|
|
|
|
) &
|
|
|
|
|
_db.remoteAssetEntity.deletedAt.isNull(),
|
|
|
|
|
),
|
|
|
|
|
])
|
|
|
|
|
..where(_db.personEntity.isHidden.equals(false))
|
|
|
|
|
..groupBy([_db.personEntity.id], having: _db.assetFaceEntity.id.count().isBiggerOrEqualValue(3))
|
|
|
|
|
..where(_db.remoteAssetEntity.deletedAt.isNull())
|
|
|
|
|
..groupBy(
|
|
|
|
|
[_db.personEntity.id],
|
|
|
|
|
having: Expression.or([
|
|
|
|
|
_db.assetFaceEntity.id.count().isBiggerOrEqualValue(3),
|
|
|
|
|
_db.personEntity.name.equals('').not(),
|
|
|
|
|
]),
|
|
|
|
|
)
|
|
|
|
|
..orderBy([
|
|
|
|
|
OrderingTerm(expression: _db.personEntity.name.equals('').not(), mode: OrderingMode.desc),
|
|
|
|
|
OrderingTerm(expression: _db.assetFaceEntity.id.count(), mode: OrderingMode.desc),
|
|
|
|
|
|