Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 7 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions server/src/infra/repositories/person.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,16 +171,18 @@ 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')
.distinct(true)
martabal marked this conversation as resolved.
Show resolved Hide resolved
.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,
};
}

Expand Down Expand Up @@ -223,8 +225,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;
Expand Down
2 changes: 1 addition & 1 deletion server/src/infra/sql/person.repository.sql
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ LIMIT

-- PersonRepository.getStatistics
SELECT DISTINCT
COUNT(DISTINCT ("face"."id")) AS "cnt"
COUNT(DISTINCT ("asset"."id")) AS "count"
FROM
"asset_faces" "face"
LEFT JOIN "assets" "asset" ON "asset"."id" = "face"."assetId"
Expand Down
Loading