mirror of
https://github.com/immich-app/immich
synced 2025-11-07 17:27:20 +00:00
fix(server): searching with both personIds and withPeople (#13254)
* use cte * linting
This commit is contained in:
parent
5b00bc499f
commit
063969ca05
2 changed files with 11 additions and 29 deletions
|
|
@ -1,4 +1,5 @@
|
|||
import _ from 'lodash';
|
||||
import { AssetFaceEntity } from 'src/entities/asset-face.entity';
|
||||
import { AssetEntity } from 'src/entities/asset.entity';
|
||||
import { AssetSearchBuilderOptions } from 'src/interfaces/search.interface';
|
||||
import { Between, IsNull, LessThanOrEqual, MoreThanOrEqual, Not, SelectQueryBuilder } from 'typeorm';
|
||||
|
|
@ -91,7 +92,6 @@ export function searchAssetBuilder(
|
|||
withPeople,
|
||||
withSmartInfo,
|
||||
personIds,
|
||||
withExif,
|
||||
withStacked,
|
||||
trashedAfter,
|
||||
trashedBefore,
|
||||
|
|
@ -128,15 +128,14 @@ export function searchAssetBuilder(
|
|||
}
|
||||
|
||||
if (personIds && personIds.length > 0) {
|
||||
builder
|
||||
.leftJoin(`${builder.alias}.faces`, 'faces')
|
||||
.andWhere('faces.personId IN (:...personIds)', { personIds })
|
||||
.addGroupBy(`${builder.alias}.id`)
|
||||
.having('COUNT(DISTINCT faces.personId) = :personCount', { personCount: personIds.length });
|
||||
|
||||
if (withExif) {
|
||||
builder.addGroupBy('exifInfo.assetId');
|
||||
}
|
||||
const cte = builder
|
||||
.createQueryBuilder()
|
||||
.select('faces."assetId"')
|
||||
.from(AssetFaceEntity, 'faces')
|
||||
.where('faces."personId" IN (:...personIds)', { personIds })
|
||||
.groupBy(`faces."assetId"`)
|
||||
.having(`COUNT(DISTINCT faces."personId") = :personCount`, { personCount: personIds.length });
|
||||
builder.addCommonTableExpression(cte, 'face_ids').innerJoin('face_ids', 'a', 'a."assetId" = asset.id');
|
||||
}
|
||||
|
||||
if (withStacked) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue