Files
immich/server/src/queries/person.repository.sql
T
2026-05-28 13:47:38 +02:00

551 lines
12 KiB
SQL

-- NOTE: This file is auto generated by ./sql-generator
-- PersonRepository.reassignFaces
update "asset_face"
set
-- PersonRepository.delete
delete from "person"
where
"person"."id" in ($1)
-- PersonRepository.getFileSamples
select
"id",
"thumbnailPath"
from
"person"
where
"thumbnailPath" != ''
limit
3
-- PersonRepository.getAllForUser
select distinct
on ("person"."faceClusterId") "person".*
from
"person"
inner join "asset_face" on "asset_face"."faceClusterId" = "person"."faceClusterId"
inner join "asset" on "asset_face"."assetId" = "asset"."id"
and "asset"."visibility" = 'timeline'
and "asset"."deletedAt" is null
where
(
"person"."ownerId" = $1
or (
exists (
select
from
"partner"
where
"partner"."sharedById" = "person"."ownerId"
and "partner"."sharedWithId" = $2
and (
$3 = any ("partner"."permissions")
or "partner"."permissions" @> $4
)
)
or exists (
select
from
"album_user"
where
"album_user"."albumId" in (
select
"album_user"."albumId"
from
"album_user"
where
"album_user"."userId" = $5
)
and "album_user"."userId" = "person"."ownerId"
and (
$6 = any ("album_user"."permissions")
or "album_user"."permissions" @> $7
)
)
)
)
and "asset_face"."deletedAt" is null
and "asset_face"."isVisible" is true
and "person"."isHidden" = $8
group by
"person"."id"
having
(
"person"."name" != $9
or count("asset_face"."assetId") >= $10
)
order by
"person"."faceClusterId",
"person"."ownerId" = $11 desc,
"person"."isHidden" asc,
"person"."isFavorite" desc,
NULLIF(person.name, '') is null asc,
count("asset_face"."assetId") desc,
NULLIF(person.name, '') asc nulls last,
"person"."createdAt"
limit
$12
offset
$13
-- PersonRepository.getAllWithoutFaces
select
"person".*
from
"person"
left join "asset_face" on "asset_face"."faceClusterId" = "person"."faceClusterId"
where
"asset_face"."deletedAt" is null
and "asset_face"."isVisible" is true
group by
"person"."id"
having
count("asset_face"."assetId") = $1
-- PersonRepository.getFaces
select
"asset_face".*,
(
select
to_json(obj)
from
(
select
"person".*
from
"person"
where
"person"."faceClusterId" = "asset_face"."faceClusterId"
order by
"person"."ownerId" = (
select
"asset"."ownerId"
from
"asset"
where
"asset"."id" = "asset_face"."assetId"
) desc
limit
$1
) as obj
) as "person"
from
"asset_face"
where
"asset_face"."assetId" = $2
and "asset_face"."deletedAt" is null
and "asset_face"."isVisible" = $3
order by
"asset_face"."boundingBoxX1" asc
-- PersonRepository.getFaceById
select
"asset_face".*,
(
select
to_json(obj)
from
(
select
"person".*
from
"person"
where
"person"."faceClusterId" = "asset_face"."faceClusterId"
order by
"person"."ownerId" = (
select
"asset"."ownerId"
from
"asset"
where
"asset"."id" = "asset_face"."assetId"
) desc
limit
$1
) as obj
) as "person"
from
"asset_face"
where
"asset_face"."id" = $2
and "asset_face"."deletedAt" is null
-- PersonRepository.getFaceForFacialRecognitionJob
select
"asset_face"."id",
"asset_face"."faceClusterId",
"asset_face"."sourceType",
(
select
to_json(obj)
from
(
select
"asset"."ownerId",
"asset"."visibility",
"asset"."fileCreatedAt"
from
"asset"
where
"asset"."id" = "asset_face"."assetId"
) as obj
) as "asset",
(
select
to_json(obj)
from
(
select
"face_search".*
from
"face_search"
where
"face_search"."faceId" = "asset_face"."id"
) as obj
) as "faceSearch"
from
"asset_face"
where
"asset_face"."id" = $1
and "asset_face"."deletedAt" is null
-- PersonRepository.getDataForThumbnailGenerationJob
select
"person"."ownerId",
"asset_face"."boundingBoxX1" as "x1",
"asset_face"."boundingBoxY1" as "y1",
"asset_face"."boundingBoxX2" as "x2",
"asset_face"."boundingBoxY2" as "y2",
"asset_face"."imageWidth" as "oldWidth",
"asset_face"."imageHeight" as "oldHeight",
"asset"."type",
"asset"."originalPath",
"asset_exif"."orientation" as "exifOrientation",
(
select
"asset_file"."path"
from
"asset_file"
where
"asset_file"."assetId" = "asset"."id"
and "asset_file"."type" = 'preview'
and "asset_file"."isEdited" = false
) as "previewPath"
from
"person"
inner join "asset_face" on "asset_face"."id" = "person"."faceAssetId"
inner join "asset" on "asset_face"."assetId" = "asset"."id"
left join "asset_exif" on "asset_exif"."assetId" = "asset"."id"
where
"person"."id" = $1
and "asset_face"."deletedAt" is null
-- PersonRepository.reassignFace
update "asset_face"
set
"faceClusterId" = $1
where
"asset_face"."id" = $2
-- PersonRepository.getByName
with
"similarity_threshold" as (
select
set_config('pg_trgm.word_similarity_threshold', '0.5', true) as "thresh"
)
select
"person".*
from
"similarity_threshold",
"person"
where
"person"."ownerId" = $1
and f_unaccent ("person"."name") %> f_unaccent ($2)
order by
f_unaccent ("person"."name") <->>> f_unaccent ($3),
"person"."ownerId" = $4 desc
limit
$5
-- PersonRepository.getDistinctNames
select distinct
on (lower("person"."name")) "person"."id",
"person"."name"
from
"person"
where
(
"person"."ownerId" = $1
and "person"."name" != $2
)
-- PersonRepository.getStatistics
select
count(distinct ("asset"."id")) as "count"
from
"asset_face"
left join "asset" on "asset"."id" = "asset_face"."assetId"
and "asset"."visibility" = 'timeline'
and "asset"."deletedAt" is null
where
(
"asset"."ownerId" = $1
or exists (
select
from
"partner"
where
"partner"."sharedById" = "asset"."ownerId"
and "partner"."sharedWithId" = $2
and (
$3 = any ("partner"."permissions")
or "partner"."permissions" @> $4
)
)
or exists (
select
from
"album_asset"
inner join "album_user" on "album_user"."albumId" = "album_asset"."albumId"
and "album_user"."userId" = $5
where
"album_asset"."assetId" = "asset"."id"
and "album_user"."albumId" in (
select
"album_user"."albumId"
from
"album_user"
where
"album_user"."userId" = "asset"."ownerId"
and (
$6 = any ("album_user"."permissions")
or "album_user"."permissions" @> $7
)
)
)
)
and "asset_face"."deletedAt" is null
and "asset_face"."isVisible" is true
and "asset_face"."faceClusterId" = (
select
"person"."faceClusterId"
from
"person"
where
"person"."id" = $8
)
-- PersonRepository.getNumberOfPeople
select
coalesce(count(*), 0) as "total",
coalesce(
count(*) filter (
where
"isHidden" = $1
),
0
) as "hidden"
from
"person"
where
exists (
select
from
"asset_face"
where
"asset_face"."faceClusterId" = "person"."faceClusterId"
and "asset_face"."deletedAt" is null
and "asset_face"."isVisible" = $2
and exists (
select
from
"asset"
where
"asset"."id" = "asset_face"."assetId"
and "asset"."visibility" = 'timeline'
and "asset"."deletedAt" is null
)
)
and (
"person"."ownerId" = $3
or (
exists (
select
from
"partner"
where
"partner"."sharedById" = "person"."ownerId"
and "partner"."sharedWithId" = $4
and (
$5 = any ("partner"."permissions")
or "partner"."permissions" @> $6
)
)
or exists (
select
from
"album_user"
where
"album_user"."albumId" in (
select
"album_user"."albumId"
from
"album_user"
where
"album_user"."userId" = $7
)
and "album_user"."userId" = "person"."ownerId"
and (
$8 = any ("album_user"."permissions")
or "album_user"."permissions" @> $9
)
)
)
)
-- PersonRepository.refreshFaces
with
"added_embeddings" as (
insert into
"face_search" ("faceId", "embedding")
values
($1, $2)
)
select
from
(
select
1
) as "dummy"
-- PersonRepository.getFacesByIds
select
"asset_face".*,
(
select
to_json(obj)
from
(
select
"person".*
from
"person"
where
"person"."faceClusterId" = "asset_face"."faceClusterId"
order by
"person"."ownerId" = (
select
"asset"."ownerId"
from
"asset"
where
"asset"."id" = "asset_face"."assetId"
) desc
limit
$1
) as obj
) as "person"
from
"asset_face"
inner join "person" on "person"."faceClusterId" = "asset_face"."faceClusterId"
where
"person"."id" in ($2)
and "asset_face"."assetId" in ($3)
and "asset_face"."deletedAt" is null
-- PersonRepository.getRandomFace
select
"asset_face".*
from
"asset_face"
inner join "person" on "asset_face"."faceClusterId" = "person"."faceClusterId"
and "person"."id" = $1
where
"asset_face"."assetId" in (
select
"asset"."id"
from
"asset"
where
(
"asset"."ownerId" = "person"."ownerId"
or exists (
select
from
"partner"
where
"partner"."sharedById" = "asset"."ownerId"
and "partner"."sharedWithId" = "person"."ownerId"
and (
$2 = any ("partner"."permissions")
or "partner"."permissions" @> $3
)
)
or exists (
select
from
"album_asset"
inner join "album_user" on "album_user"."albumId" = "album_asset"."albumId"
and "album_user"."userId" = "person"."ownerId"
where
"album_asset"."assetId" = "asset"."id"
and "album_user"."albumId" in (
select
"album_user"."albumId"
from
"album_user"
where
"album_user"."userId" = "asset"."ownerId"
and (
$4 = any ("album_user"."permissions")
or "album_user"."permissions" @> $5
)
)
)
)
)
and "asset_face"."deletedAt" is null
and "asset_face"."isVisible" is true
-- PersonRepository.getLatestFaceDate
select
max("asset_job_status"."facesRecognizedAt")::text as "latestDate"
from
"asset_job_status"
-- PersonRepository.deleteAssetFace
delete from "asset_face"
where
"asset_face"."id" = $1
-- PersonRepository.softDeleteAssetFaces
update "asset_face"
set
"deletedAt" = $1
where
"asset_face"."id" = $2
-- PersonRepository.getForPeopleDelete
select
"id",
"thumbnailPath"
from
"person"
where
"id" in ($1)
-- PersonRepository.getForFeatureFaceUpdate
select
"asset_face"."id"
from
"asset_face"
inner join "person" on "person"."faceClusterId" = "asset_face"."faceClusterId"
and "person"."id" = $1
inner join "asset" on "asset"."id" = "asset_face"."assetId"
and "asset"."isOffline" = $2
where
"asset_face"."assetId" = $3