|
|
|
@ -38,11 +38,6 @@ export interface PersonStatistics {
|
|
|
|
assets: number;
|
|
|
|
assets: number;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export interface PeopleStatistics {
|
|
|
|
|
|
|
|
total: number;
|
|
|
|
|
|
|
|
hidden: number;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export interface DeleteFacesOptions {
|
|
|
|
export interface DeleteFacesOptions {
|
|
|
|
sourceType: SourceType;
|
|
|
|
sourceType: SourceType;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -151,7 +146,7 @@ export class PersonRepository {
|
|
|
|
.innerJoin('assets', (join) =>
|
|
|
|
.innerJoin('assets', (join) =>
|
|
|
|
join
|
|
|
|
join
|
|
|
|
.onRef('asset_faces.assetId', '=', 'assets.id')
|
|
|
|
.onRef('asset_faces.assetId', '=', 'assets.id')
|
|
|
|
.on('assets.visibility', '!=', AssetVisibility.ARCHIVE)
|
|
|
|
.on('assets.visibility', '=', sql.lit(AssetVisibility.TIMELINE))
|
|
|
|
.on('assets.deletedAt', 'is', null),
|
|
|
|
.on('assets.deletedAt', 'is', null),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.where('person.ownerId', '=', userId)
|
|
|
|
.where('person.ownerId', '=', userId)
|
|
|
|
@ -341,7 +336,7 @@ export class PersonRepository {
|
|
|
|
join
|
|
|
|
join
|
|
|
|
.onRef('assets.id', '=', 'asset_faces.assetId')
|
|
|
|
.onRef('assets.id', '=', 'asset_faces.assetId')
|
|
|
|
.on('asset_faces.personId', '=', personId)
|
|
|
|
.on('asset_faces.personId', '=', personId)
|
|
|
|
.on('assets.visibility', '!=', AssetVisibility.ARCHIVE)
|
|
|
|
.on('assets.visibility', '=', sql.lit(AssetVisibility.TIMELINE))
|
|
|
|
.on('assets.deletedAt', 'is', null),
|
|
|
|
.on('assets.deletedAt', 'is', null),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.select((eb) => eb.fn.count(eb.fn('distinct', ['assets.id'])).as('count'))
|
|
|
|
.select((eb) => eb.fn.count(eb.fn('distinct', ['assets.id'])).as('count'))
|
|
|
|
@ -354,35 +349,31 @@ export class PersonRepository {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@GenerateSql({ params: [DummyValue.UUID] })
|
|
|
|
@GenerateSql({ params: [DummyValue.UUID] })
|
|
|
|
async getNumberOfPeople(userId: string): Promise<PeopleStatistics> {
|
|
|
|
getNumberOfPeople(userId: string) {
|
|
|
|
const items = await this.db
|
|
|
|
const zero = sql.lit(0);
|
|
|
|
|
|
|
|
return this.db
|
|
|
|
.selectFrom('person')
|
|
|
|
.selectFrom('person')
|
|
|
|
.innerJoin('asset_faces', 'asset_faces.personId', 'person.id')
|
|
|
|
.where((eb) =>
|
|
|
|
.where('person.ownerId', '=', userId)
|
|
|
|
eb.exists((eb) =>
|
|
|
|
.where('asset_faces.deletedAt', 'is', null)
|
|
|
|
eb
|
|
|
|
.innerJoin('assets', (join) =>
|
|
|
|
.selectFrom('asset_faces')
|
|
|
|
join
|
|
|
|
.whereRef('asset_faces.personId', '=', 'person.id')
|
|
|
|
.onRef('assets.id', '=', 'asset_faces.assetId')
|
|
|
|
.where('asset_faces.deletedAt', 'is', null)
|
|
|
|
.on('assets.deletedAt', 'is', null)
|
|
|
|
.where((eb) =>
|
|
|
|
.on('assets.visibility', '!=', AssetVisibility.ARCHIVE),
|
|
|
|
eb.exists((eb) =>
|
|
|
|
)
|
|
|
|
eb
|
|
|
|
.select((eb) => eb.fn.count(eb.fn('distinct', ['person.id'])).as('total'))
|
|
|
|
.selectFrom('assets')
|
|
|
|
.select((eb) =>
|
|
|
|
.whereRef('assets.id', '=', 'asset_faces.assetId')
|
|
|
|
eb.fn
|
|
|
|
.where('assets.visibility', '=', sql.lit(AssetVisibility.TIMELINE))
|
|
|
|
.count(eb.fn('distinct', ['person.id']))
|
|
|
|
.where('assets.deletedAt', 'is', null),
|
|
|
|
.filterWhere('person.isHidden', '=', true)
|
|
|
|
),
|
|
|
|
.as('hidden'),
|
|
|
|
),
|
|
|
|
|
|
|
|
),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.executeTakeFirst();
|
|
|
|
.where('person.ownerId', '=', userId)
|
|
|
|
|
|
|
|
.select((eb) => eb.fn.coalesce(eb.fn.countAll<number>(), zero).as('total'))
|
|
|
|
if (items == undefined) {
|
|
|
|
.select((eb) => eb.fn.coalesce(eb.fn.countAll<number>().filterWhere('isHidden', '=', true), zero).as('hidden'))
|
|
|
|
return { total: 0, hidden: 0 };
|
|
|
|
.executeTakeFirstOrThrow();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
|
|
total: Number(items.total),
|
|
|
|
|
|
|
|
hidden: Number(items.hidden),
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
create(person: Insertable<Person>) {
|
|
|
|
create(person: Insertable<Person>) {
|
|
|
|
|