fix(server): Sort stacked assets by creation date (#24033)

* feat: add ordering by file creation date in asset and stack repositories

* refactor: update asset aggregation to include JSON formatting and ordering by creation date

* refactor: add ordering by file creation date in asset aggregation queries

* fix: types

---------

Co-authored-by: Jason Rasmussen <jason@rasm.me>
This commit is contained in:
Timon 2026-08-18 23:38:58 +02:00 committed by GitHub
parent 17d4e39af3
commit 3c279983bc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 10 additions and 5 deletions

View file

@ -54,6 +54,8 @@ select
"asset"."deletedAt" is null
and "asset"."stackId" = "stack"."id"
and "asset"."visibility" in ('archive', 'timeline')
order by
"asset"."fileCreatedAt" asc
) as agg
) as "assets"
from
@ -139,6 +141,8 @@ select
"asset"."deletedAt" is null
and "asset"."stackId" = "stack"."id"
and "asset"."visibility" in ('archive', 'timeline')
order by
"asset"."fileCreatedAt" asc
) as agg
) as "assets"
from

View file

@ -594,10 +594,10 @@ export class AssetRepository {
eb
.selectFrom('asset as stacked')
.selectAll('stack')
.select((eb) =>
eb
.fn<ShallowDehydrateObject<Selectable<AssetTable>>>('array_agg', [eb.table('stacked')])
.as('assets'),
.select(
sql<
ShallowDehydrateObject<Selectable<AssetTable>>[]
>`array_agg(to_json(stacked) ORDER BY stacked."fileCreatedAt" ASC)`.as('assets'),
)
.whereRef('stacked.stackId', '=', 'stack.id')
.whereRef('stacked.id', '!=', 'stack.primaryAssetId')

View file

@ -41,7 +41,8 @@ const withAssets = (eb: ExpressionBuilder<DB, 'stack'>, withTags = false) => {
.select((eb) => eb.fn.toJson('exifInfo').as('exifInfo'))
.where('asset.deletedAt', 'is', null)
.whereRef('asset.stackId', '=', 'stack.id')
.$call(withDefaultVisibility),
.$call(withDefaultVisibility)
.orderBy('asset.fileCreatedAt', 'asc'),
).as('assets');
};