Skip to content

High performance self-hosted photo and video management solution.

fix(server): no exif metadata in the deduplication utility (#15585)

Merta6ace5151c11
diff --git a/server/src/queries/asset.repository.sql b/server/src/queries/asset.repository.sql
index 67f9f39c84..948f7dd114 100644
--- a/server/src/queries/asset.repository.sql
+++ b/server/src/queries/asset.repository.sql
@@ -306,17 +306,26 @@ order by
with
"duplicates" as (
select
- "duplicateId",
- jsonb_agg("assets") as "assets"
+ "assets"."duplicateId",
+ jsonb_agg("asset") as "assets"
from
"assets"
+ left join lateral (
+ select
+ "assets".*,
+ "exif" as "exifInfo"
+ from
+ "exif"
+ where
+ "exif"."assetId" = "assets"."id"
+ ) as "asset" on true
where
- "ownerId" = $1::uuid
- and "duplicateId" is not null
- and "deletedAt" is null
- and "isVisible" = $2
+ "assets"."ownerId" = $1::uuid
+ and "assets"."duplicateId" is not null
+ and "assets"."deletedAt" is null
+ and "assets"."isVisible" = $2
group by
- "duplicateId"
+ "assets"."duplicateId"
),
"unique" as (
select
diff --git a/server/src/repositories/asset.repository.ts b/server/src/repositories/asset.repository.ts
index 6bb253d183..b39781209e 100644
--- a/server/src/repositories/asset.repository.ts
+++ b/server/src/repositories/asset.repository.ts
@@ -677,13 +677,23 @@ export class AssetRepository implements IAssetRepository {
.with('duplicates', (qb) =>
qb
.selectFrom('assets')
- .select('duplicateId')
- .select((eb) => eb.fn<Assets[]>('jsonb_agg', [eb.table('assets')]).as('assets'))
- .where('ownerId', '=', asUuid(userId))
- .where('duplicateId', 'is not', null)
- .where('deletedAt', 'is', null)
- .where('isVisible', '=', true)
- .groupBy('duplicateId'),
+ .leftJoinLateral(
+ (qb) =>
+ qb
+ .selectFrom('exif')
+ .selectAll('assets')
+ .select((eb) => eb.table('exif').as('exifInfo'))
+ .whereRef('exif.assetId', '=', 'assets.id')
+ .as('asset'),
+ (join) => join.onTrue(),
+ )
+ .select('assets.duplicateId')
+ .select((eb) => eb.fn('jsonb_agg', [eb.table('asset')]).as('assets'))
+ .where('assets.ownerId', '=', asUuid(userId))
+ .where('assets.duplicateId', 'is not', null)
+ .where('assets.deletedAt', 'is', null)
+ .where('assets.isVisible', '=', true)
+ .groupBy('assets.duplicateId'),
)
.with('unique', (qb) =>
qb