mirror of
https://github.com/immich-app/immich.git
synced 2025-07-09 03:04:16 -04:00
stack as tuple
This commit is contained in:
parent
8837f5b4fb
commit
a3a2ced3a9
@ -83,10 +83,17 @@ export class TimeBucketAssetResponseDto implements TimeBucketAssets {
|
|||||||
@ApiProperty({ type: 'array', items: { type: 'string', nullable: true } })
|
@ApiProperty({ type: 'array', items: { type: 'string', nullable: true } })
|
||||||
duration!: (string | null)[];
|
duration!: (string | null)[];
|
||||||
|
|
||||||
stackCount?: number[];
|
// id, count
|
||||||
|
@ApiProperty({
|
||||||
@ApiProperty({ type: 'array', items: { type: 'string', nullable: true } })
|
type: 'array',
|
||||||
stackId?: (string | null)[];
|
items: {
|
||||||
|
type: 'array',
|
||||||
|
nullable: true,
|
||||||
|
items: { oneOf: [{ type: 'string' }, { type: 'number' }], minItems: 2, maxItems: 2 },
|
||||||
|
},
|
||||||
|
description: 'The stack ID and stack asset count as a tuple',
|
||||||
|
})
|
||||||
|
stack?: ([string, number] | null)[];
|
||||||
|
|
||||||
@ApiProperty({ type: 'array', items: { type: 'string', nullable: true } })
|
@ApiProperty({ type: 'array', items: { type: 'string', nullable: true } })
|
||||||
projectionType!: (string | null)[];
|
projectionType!: (string | null)[];
|
||||||
|
@ -652,14 +652,15 @@ export class AssetRepository {
|
|||||||
(eb) =>
|
(eb) =>
|
||||||
eb
|
eb
|
||||||
.selectFrom('assets as stacked')
|
.selectFrom('assets as stacked')
|
||||||
.select((eb) => eb.fn.coalesce(eb.fn.count(eb.table('stacked')), eb.lit(0)).as('stackCount'))
|
.select(sql`json_build_array(stacked."stackId", count('stacked'))`.as('stack'))
|
||||||
.whereRef('stacked.stackId', '=', 'assets.stackId')
|
.whereRef('stacked.stackId', '=', 'assets.stackId')
|
||||||
.where('stacked.deletedAt', 'is', null)
|
.where('stacked.deletedAt', 'is', null)
|
||||||
.where('stacked.isArchived', '=', false)
|
.where('stacked.isArchived', '=', false)
|
||||||
|
.groupBy('stacked.stackId')
|
||||||
.as('stacked_assets'),
|
.as('stacked_assets'),
|
||||||
(join) => join.onTrue(),
|
(join) => join.onTrue(),
|
||||||
)
|
)
|
||||||
.select(['assets.stackId', 'stackCount']),
|
.select('stack'),
|
||||||
)
|
)
|
||||||
.$if(!!options.assetType, (qb) => qb.where('assets.type', '=', options.assetType!))
|
.$if(!!options.assetType, (qb) => qb.where('assets.type', '=', options.assetType!))
|
||||||
.$if(options.isDuplicate !== undefined, (qb) =>
|
.$if(options.isDuplicate !== undefined, (qb) =>
|
||||||
@ -690,12 +691,7 @@ export class AssetRepository {
|
|||||||
eb.fn.coalesce(eb.fn('array_agg', ['status']), sql.lit('{}')).as('status'),
|
eb.fn.coalesce(eb.fn('array_agg', ['status']), sql.lit('{}')).as('status'),
|
||||||
eb.fn.coalesce(eb.fn('array_agg', ['thumbhash']), sql.lit('{}')).as('thumbhash'),
|
eb.fn.coalesce(eb.fn('array_agg', ['thumbhash']), sql.lit('{}')).as('thumbhash'),
|
||||||
])
|
])
|
||||||
.$if(!!options.withStacked, (qb) =>
|
.$if(!!options.withStacked, (qb) => qb.select((eb) => eb.fn('array_agg', ['stack']).as('stack'))),
|
||||||
qb.select((eb) => [
|
|
||||||
eb.fn('array_agg', ['stackCount']).as('stackCount'),
|
|
||||||
eb.fn('array_agg', ['stackId']).as('stackId'),
|
|
||||||
]),
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
.selectFrom('agg')
|
.selectFrom('agg')
|
||||||
.select(sql<string>`to_json(agg)::text`.as('assets'));
|
.select(sql<string>`to_json(agg)::text`.as('assets'));
|
||||||
|
@ -19,8 +19,7 @@ export type TimeBucketAssets = {
|
|||||||
isImage: number[];
|
isImage: number[];
|
||||||
thumbhash: (string | null)[];
|
thumbhash: (string | null)[];
|
||||||
localDateTime: string[];
|
localDateTime: string[];
|
||||||
stackCount?: number[];
|
stack?: ([string, number] | null)[];
|
||||||
stackId?: (string | null)[];
|
|
||||||
duration: (string | null)[];
|
duration: (string | null)[];
|
||||||
projectionType: (string | null)[];
|
projectionType: (string | null)[];
|
||||||
livePhotoVideoId: (string | null)[];
|
livePhotoVideoId: (string | null)[];
|
||||||
|
@ -437,11 +437,11 @@ export class AssetBucket {
|
|||||||
people: [],
|
people: [],
|
||||||
projectionType: bucketAssets.projectionType[i],
|
projectionType: bucketAssets.projectionType[i],
|
||||||
ratio: bucketAssets.ratio[i],
|
ratio: bucketAssets.ratio[i],
|
||||||
stack: bucketAssets.stackId?.[i]
|
stack: bucketAssets.stack?.[i]
|
||||||
? {
|
? {
|
||||||
id: bucketAssets.stackId[i]!,
|
id: bucketAssets.stack[i]![0] as string,
|
||||||
primaryAssetId: bucketAssets.id[i],
|
primaryAssetId: bucketAssets.id[i],
|
||||||
assetCount: bucketAssets.stackCount![i],
|
assetCount: bucketAssets.stack[i]![1] as number,
|
||||||
}
|
}
|
||||||
: null,
|
: null,
|
||||||
thumbhash: bucketAssets.thumbhash[i],
|
thumbhash: bucketAssets.thumbhash[i],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user