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 21:38:58 +00:00
committed by GitHub
co-authored by Jason Rasmussen
parent 17d4e39af3
commit 3c279983bc
3 changed files with 10 additions and 5 deletions
+4
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
+4 -4
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')
+2 -1
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');
};