fix(server): incorrect number of assets for a person (#7602)

* fix: incorrect number of assets

* fix: tests

* pr feedback

* fix: e2e test

* fix: e2e test

* fix: e2e test

* feat: more tests
This commit is contained in:
martin 2024-03-05 00:11:54 +01:00 committed by GitHub
parent 5bc13c49a4
commit 6ab404597c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 60 additions and 20 deletions

View file

@ -171,16 +171,17 @@ export class PersonRepository implements IPersonRepository {
@GenerateSql({ params: [DummyValue.UUID] })
async getStatistics(personId: string): Promise<PersonStatistics> {
const items = await this.assetFaceRepository
.createQueryBuilder('face')
.leftJoin('face.asset', 'asset')
.where('face.personId = :personId', { personId })
.andWhere('asset.isArchived = false')
.andWhere('asset.deletedAt IS NULL')
.andWhere('asset.livePhotoVideoId IS NULL')
.select('COUNT(DISTINCT(asset.id))', 'count')
.getRawOne();
return {
assets: await this.assetFaceRepository
.createQueryBuilder('face')
.leftJoin('face.asset', 'asset')
.where('face.personId = :personId', { personId })
.andWhere('asset.isArchived = false')
.andWhere('asset.deletedAt IS NULL')
.andWhere('asset.livePhotoVideoId IS NULL')
.distinct(true)
.getCount(),
assets: items.count ?? 0,
};
}
@ -223,8 +224,8 @@ export class PersonRepository implements IPersonRepository {
.getRawOne();
const result: PeopleStatistics = {
total: items ? Number.parseInt(items.total) : 0,
hidden: items ? Number.parseInt(items.hidden) : 0,
total: items.total ?? 0,
hidden: items.hidden ?? 0,
};
return result;

View file

@ -224,8 +224,8 @@ LIMIT
20
-- PersonRepository.getStatistics
SELECT DISTINCT
COUNT(DISTINCT ("face"."id")) AS "cnt"
SELECT
COUNT(DISTINCT ("asset"."id")) AS "count"
FROM
"asset_faces" "face"
LEFT JOIN "assets" "asset" ON "asset"."id" = "face"."assetId"