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:
@@ -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
|
||||
|
||||
@@ -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')
|
||||
|
||||
@@ -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');
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user