Files
immich/server/src/queries/duplicate.repository.sql

120 lines
2.2 KiB
MySQL
Raw Normal View History

2025-06-12 14:23:02 -04:00
-- NOTE: This file is auto generated by ./sql-generator
-- DuplicateRepository.getAll
with
"duplicates" as (
select
2025-07-14 10:13:06 -04:00
"asset"."duplicateId",
2025-06-12 14:23:02 -04:00
json_agg(
2025-07-14 10:13:06 -04:00
"asset2"
2025-06-12 14:23:02 -04:00
order by
2025-07-14 10:13:06 -04:00
"asset"."localDateTime" asc
2025-06-12 14:23:02 -04:00
) as "assets"
from
2025-07-14 10:13:06 -04:00
"asset"
2025-06-12 14:23:02 -04:00
left join lateral (
select
2025-07-14 10:13:06 -04:00
"asset".*,
"asset_exif" as "exifInfo"
2025-06-12 14:23:02 -04:00
from
2025-07-14 10:13:06 -04:00
"asset_exif"
2025-06-12 14:23:02 -04:00
where
2025-07-14 10:13:06 -04:00
"asset_exif"."assetId" = "asset"."id"
) as "asset2" on true
2025-06-12 14:23:02 -04:00
where
2025-07-14 10:13:06 -04:00
"asset"."visibility" in ('archive', 'timeline')
and "asset"."ownerId" = $1::uuid
and "asset"."duplicateId" is not null
and "asset"."deletedAt" is null
and "asset"."stackId" is null
2025-06-12 14:23:02 -04:00
group by
2025-07-14 10:13:06 -04:00
"asset"."duplicateId"
2025-06-12 14:23:02 -04:00
),
"unique" as (
select
"duplicateId"
from
"duplicates"
where
json_array_length("assets") = $2
),
"removed_unique" as (
2025-07-14 10:13:06 -04:00
update "asset"
2025-06-12 14:23:02 -04:00
set
"duplicateId" = $3
from
"unique"
where
2025-07-14 10:13:06 -04:00
"asset"."duplicateId" = "unique"."duplicateId"
2025-06-12 14:23:02 -04:00
)
select
*
from
"duplicates"
where
not exists (
select
from
"unique"
where
"unique"."duplicateId" = "duplicates"."duplicateId"
)
-- DuplicateRepository.delete
2025-07-14 10:13:06 -04:00
update "asset"
set
"duplicateId" = $1
where
"ownerId" = $2
and "duplicateId" = $3
-- DuplicateRepository.deleteAll
2025-07-14 10:13:06 -04:00
update "asset"
set
"duplicateId" = $1
where
"ownerId" = $2
and "duplicateId" in ($3)
2025-06-12 14:23:02 -04:00
-- DuplicateRepository.search
begin
set
local vchordrq.probes = 1
with
"cte" as (
select
2025-07-14 10:13:06 -04:00
"asset"."id" as "assetId",
"asset"."duplicateId",
2025-06-12 14:23:02 -04:00
smart_search.embedding <=> $1 as "distance"
from
2025-07-14 10:13:06 -04:00
"asset"
inner join "smart_search" on "asset"."id" = "smart_search"."assetId"
2025-06-12 14:23:02 -04:00
where
2025-07-14 10:13:06 -04:00
"asset"."visibility" in ('archive', 'timeline')
and "asset"."ownerId" = any ($2::uuid[])
and "asset"."deletedAt" is null
and "asset"."type" = $3
and "asset"."id" != $4::uuid
and "asset"."stackId" is null
2025-06-12 14:23:02 -04:00
order by
"distance"
limit
$5
)
select
*
from
"cte"
where
"cte"."distance" <= $6
commit
-- DuplicateRepository.merge
2025-07-14 10:13:06 -04:00
update "asset"
2025-06-12 14:23:02 -04:00
set
where
(
"duplicateId" = any ($1::uuid[])
or "id" = any ($2::uuid[])
)