feat(server): sort images in duplicate groups by date (#18347)

This restores behaviour introduced in
562fec6e2bc293ff977730ce809a7ee182eb3eef and lost in
2e12c46980b45072beb0f4ba125f821053b13851.
This commit is contained in:
Geoffrey Frogeye 2025-05-19 23:27:30 +02:00 committed by GitHub
parent c8641d24f6
commit 00a77c2d6a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 8 deletions

View File

@ -296,7 +296,11 @@ with
"duplicates" as (
select
"assets"."duplicateId",
jsonb_agg("asset") as "assets"
json_agg(
"asset"
order by
"assets"."localDateTime" asc
) as "assets"
from
"assets"
left join lateral (
@ -323,7 +327,7 @@ with
from
"duplicates"
where
jsonb_array_length("assets") = $3
json_array_length("assets") = $3
),
"removed_unique" as (
update "assets"

View File

@ -649,10 +649,7 @@ export class AssetRepository {
)
.select('assets.duplicateId')
.select((eb) =>
eb
.fn('jsonb_agg', [eb.table('asset')])
.$castTo<MapAsset[]>()
.as('assets'),
eb.fn.jsonAgg('asset').orderBy('assets.localDateTime', 'asc').$castTo<MapAsset[]>().as('assets'),
)
.where('assets.ownerId', '=', asUuid(userId))
.where('assets.duplicateId', 'is not', null)
@ -666,7 +663,7 @@ export class AssetRepository {
qb
.selectFrom('duplicates')
.select('duplicateId')
.where((eb) => eb(eb.fn('jsonb_array_length', ['assets']), '=', 1)),
.where((eb) => eb(eb.fn('json_array_length', ['assets']), '=', 1)),
)
.with('removed_unique', (qb) =>
qb
@ -677,7 +674,7 @@ export class AssetRepository {
)
.selectFrom('duplicates')
.selectAll()
// TODO: compare with filtering by jsonb_array_length > 1
// TODO: compare with filtering by json_array_length > 1
.where(({ not, exists }) =>
not(exists((eb) => eb.selectFrom('unique').whereRef('unique.duplicateId', '=', 'duplicates.duplicateId'))),
)