Yaros 2025-12-10 18:20:45 +07:00 committed by GitHub
commit 013796aeab
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 21 additions and 7 deletions

@ -122,7 +122,7 @@ describe('/people', () => {
expect(status).toBe(200); expect(status).toBe(200);
expect(body).toEqual({ expect(body).toEqual({
hasNextPage: false, hasNextPage: false,
total: 11, total: 10,
hidden: 1, hidden: 1,
people: [ people: [
expect.objectContaining({ name: 'Freddy' }), expect.objectContaining({ name: 'Freddy' }),
@ -144,7 +144,7 @@ describe('/people', () => {
expect(status).toBe(200); expect(status).toBe(200);
expect(body.hasNextPage).toBe(false); expect(body.hasNextPage).toBe(false);
expect(body.total).toBe(11); // All persons expect(body.total).toBe(10); // All persons
expect(body.hidden).toBe(1); // 'hidden_person' expect(body.hidden).toBe(1); // 'hidden_person'
const people = body.people as PersonResponseDto[]; const people = body.people as PersonResponseDto[];
@ -170,7 +170,7 @@ describe('/people', () => {
expect(status).toBe(200); expect(status).toBe(200);
expect(body).toEqual({ expect(body).toEqual({
hasNextPage: false, hasNextPage: false,
total: 11, total: 10,
hidden: 1, hidden: 1,
people: [ people: [
expect.objectContaining({ name: 'Freddy' }), expect.objectContaining({ name: 'Freddy' }),
@ -195,7 +195,7 @@ describe('/people', () => {
expect(status).toBe(200); expect(status).toBe(200);
expect(body).toEqual({ expect(body).toEqual({
hasNextPage: true, hasNextPage: true,
total: 11, total: 10,
hidden: 1, hidden: 1,
people: [expect.objectContaining({ name: 'Alice' })], people: [expect.objectContaining({ name: 'Alice' })],
}); });

@ -259,8 +259,13 @@ where
and "asset"."visibility" = 'timeline' and "asset"."visibility" = 'timeline'
and "asset"."deletedAt" is null and "asset"."deletedAt" is null
) )
having
(
"person"."name" != $2
or count("asset_face"."assetId") >= $3
)
) )
and "person"."ownerId" = $2 and "person"."ownerId" = $4
-- PersonRepository.refreshFaces -- PersonRepository.refreshFaces
with with

@ -358,7 +358,7 @@ export class PersonRepository {
} }
@GenerateSql({ params: [DummyValue.UUID] }) @GenerateSql({ params: [DummyValue.UUID] })
getNumberOfPeople(userId: string) { getNumberOfPeople(userId: string, options?: PersonSearchOptions) {
const zero = sql.lit(0); const zero = sql.lit(0);
return this.db return this.db
.selectFrom('person') .selectFrom('person')
@ -368,6 +368,12 @@ export class PersonRepository {
.selectFrom('asset_face') .selectFrom('asset_face')
.whereRef('asset_face.personId', '=', 'person.id') .whereRef('asset_face.personId', '=', 'person.id')
.where('asset_face.deletedAt', 'is', null) .where('asset_face.deletedAt', 'is', null)
.having((eb) =>
eb.or([
eb('person.name', '!=', ''),
eb((innerEb) => innerEb.fn.count('asset_face.assetId'), '>=', options?.minimumFaceCount || 1),
]),
)
.where((eb) => .where((eb) =>
eb.exists((eb) => eb.exists((eb) =>
eb eb

@ -67,7 +67,10 @@ export class PersonService extends BaseService {
withHidden, withHidden,
closestFaceAssetId, closestFaceAssetId,
}); });
const { total, hidden } = await this.personRepository.getNumberOfPeople(auth.user.id); const { total, hidden } = await this.personRepository.getNumberOfPeople(auth.user.id, {
minimumFaceCount: machineLearning.facialRecognition.minFaces,
withHidden,
});
return { return {
people: items.map((person) => mapPerson(person)), people: items.map((person) => mapPerson(person)),