mirror of
https://github.com/immich-app/immich.git
synced 2025-05-31 04:05:39 -04:00
chore: simplify asset getByIds (#17699)
This commit is contained in:
parent
504930947d
commit
854ea13d6a
@ -299,51 +299,15 @@ export class AssetRepository {
|
|||||||
|
|
||||||
@GenerateSql({ params: [[DummyValue.UUID]] })
|
@GenerateSql({ params: [[DummyValue.UUID]] })
|
||||||
@ChunkedArray()
|
@ChunkedArray()
|
||||||
async getByIds(
|
getByIds(ids: string[]): Promise<AssetEntity[]> {
|
||||||
ids: string[],
|
return (
|
||||||
{ exifInfo, faces, files, library, owner, smartSearch, stack, tags }: GetByIdsRelations = {},
|
this.db
|
||||||
): Promise<AssetEntity[]> {
|
//
|
||||||
const res = await this.db
|
.selectFrom('assets')
|
||||||
.selectFrom('assets')
|
.selectAll('assets')
|
||||||
.selectAll('assets')
|
.where('assets.id', '=', anyUuid(ids))
|
||||||
.where('assets.id', '=', anyUuid(ids))
|
.execute() as Promise<AssetEntity[]>
|
||||||
.$if(!!exifInfo, withExif)
|
);
|
||||||
.$if(!!faces, (qb) =>
|
|
||||||
qb.select((eb) =>
|
|
||||||
faces?.person ? withFacesAndPeople(eb, faces.withDeleted) : withFaces(eb, faces?.withDeleted),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.$if(!!files, (qb) => qb.select(withFiles))
|
|
||||||
.$if(!!library, (qb) => qb.select(withLibrary))
|
|
||||||
.$if(!!owner, (qb) => qb.select(withOwner))
|
|
||||||
.$if(!!smartSearch, withSmartSearch)
|
|
||||||
.$if(!!stack, (qb) =>
|
|
||||||
qb
|
|
||||||
.leftJoin('asset_stack', 'asset_stack.id', 'assets.stackId')
|
|
||||||
.$if(!stack!.assets, (qb) => qb.select((eb) => eb.fn.toJson(eb.table('asset_stack')).as('stack')))
|
|
||||||
.$if(!!stack!.assets, (qb) =>
|
|
||||||
qb
|
|
||||||
.leftJoinLateral(
|
|
||||||
(eb) =>
|
|
||||||
eb
|
|
||||||
.selectFrom('assets as stacked')
|
|
||||||
.selectAll('asset_stack')
|
|
||||||
.select((eb) => eb.fn('array_agg', [eb.table('stacked')]).as('assets'))
|
|
||||||
.whereRef('stacked.stackId', '=', 'asset_stack.id')
|
|
||||||
.whereRef('stacked.id', '!=', 'asset_stack.primaryAssetId')
|
|
||||||
.where('stacked.deletedAt', 'is', null)
|
|
||||||
.where('stacked.isArchived', '=', false)
|
|
||||||
.groupBy('asset_stack.id')
|
|
||||||
.as('stacked_assets'),
|
|
||||||
(join) => join.on('asset_stack.id', 'is not', null),
|
|
||||||
)
|
|
||||||
.select((eb) => eb.fn.toJson(eb.table('stacked_assets')).as('stack')),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.$if(!!tags, (qb) => qb.select(withTags))
|
|
||||||
.execute();
|
|
||||||
|
|
||||||
return res as any as AssetEntity[];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@GenerateSql({ params: [[DummyValue.UUID]] })
|
@GenerateSql({ params: [[DummyValue.UUID]] })
|
||||||
|
Loading…
x
Reference in New Issue
Block a user