refactor: duplicate queries (#19136)

This commit is contained in:
Jason Rasmussen 2025-06-12 14:23:02 -04:00 committed by GitHub
parent 144cc8ab6d
commit 5cd186d3d4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 280 additions and 270 deletions

View file

@ -185,16 +185,6 @@ set
where
"id" = any ($2::uuid[])
-- AssetRepository.updateDuplicates
update "assets"
set
"duplicateId" = $1
where
(
"duplicateId" = any ($2::uuid[])
or "id" = any ($3::uuid[])
)
-- AssetRepository.getByChecksum
select
"assets".*
@ -349,66 +339,6 @@ select
from
"agg"
-- AssetRepository.getDuplicates
with
"duplicates" as (
select
"assets"."duplicateId",
json_agg(
"asset"
order by
"assets"."localDateTime" asc
) as "assets"
from
"assets"
left join lateral (
select
"assets".*,
"exif" as "exifInfo"
from
"exif"
where
"exif"."assetId" = "assets"."id"
) as "asset" on true
where
"assets"."visibility" in ('archive', 'timeline')
and "assets"."ownerId" = $1::uuid
and "assets"."duplicateId" is not null
and "assets"."deletedAt" is null
and "assets"."stackId" is null
group by
"assets"."duplicateId"
),
"unique" as (
select
"duplicateId"
from
"duplicates"
where
json_array_length("assets") = $2
),
"removed_unique" as (
update "assets"
set
"duplicateId" = $3
from
"unique"
where
"assets"."duplicateId" = "unique"."duplicateId"
)
select
*
from
"duplicates"
where
not exists (
select
from
"unique"
where
"unique"."duplicateId" = "duplicates"."duplicateId"
)
-- AssetRepository.getAssetIdByCity
with
"cities" as (

View file

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

View file

@ -102,39 +102,6 @@ offset
$8
commit
-- SearchRepository.searchDuplicates
begin
set
local vchordrq.probes = 1
with
"cte" as (
select
"assets"."id" as "assetId",
"assets"."duplicateId",
smart_search.embedding <=> $1 as "distance"
from
"assets"
inner join "smart_search" on "assets"."id" = "smart_search"."assetId"
where
"assets"."visibility" in ('archive', 'timeline')
and "assets"."ownerId" = any ($2::uuid[])
and "assets"."deletedAt" is null
and "assets"."type" = $3
and "assets"."id" != $4::uuid
and "assets"."stackId" is null
order by
"distance"
limit
$5
)
select
*
from
"cte"
where
"cte"."distance" <= $6
commit
-- SearchRepository.searchFaces
begin
set