refactor: query for fetching faces and people of assets (#17661)

* use json instead of jsonb

* missing condition
This commit is contained in:
Mert 2025-04-16 19:00:55 -04:00 committed by GitHub
parent ed2b54527c
commit 242a559e0f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 32 additions and 39 deletions

View file

@ -87,22 +87,26 @@ select
"assets".*,
(
select
jsonb_agg(
case
when "person"."id" is not null then jsonb_insert(
to_jsonb("asset_faces"),
'{person}'::text[],
to_jsonb("person")
)
else to_jsonb("asset_faces")
end
) as "faces"
coalesce(json_agg(agg), '[]')
from
"asset_faces"
left join "person" on "person"."id" = "asset_faces"."personId"
where
"asset_faces"."assetId" = "assets"."id"
and "asset_faces"."deletedAt" is null
(
select
"asset_faces".*,
"person" as "person"
from
"asset_faces"
left join lateral (
select
"person".*
from
"person"
where
"asset_faces"."personId" = "person"."id"
) as "person" on true
where
"asset_faces"."assetId" = "assets"."id"
and "asset_faces"."deletedAt" is null
) as agg
) as "faces",
(
select