use min year for memory time series, sql generation fixes

This commit is contained in:
mertalev
2024-12-19 20:00:42 -05:00
parent 38a82d39d3
commit 4731f271e2
10 changed files with 177 additions and 132 deletions
-62
View File
@@ -450,19 +450,6 @@ WHERE
ORDER BY
"AlbumEntity"."createdAt" DESC
-- AlbumRepository.removeAsset
DELETE FROM "albums_assets_assets"
WHERE
"albums_assets_assets"."assetsId" = $1
-- AlbumRepository.removeAssetIds
DELETE FROM "albums_assets_assets"
WHERE
(
"albumsId" = $1
AND "assetsId" IN ($2)
)
-- AlbumRepository.getAssetIds
SELECT
"albums_assets"."assetsId" AS "assetId"
@@ -471,52 +458,3 @@ FROM
WHERE
"albums_assets"."albumsId" = $1
AND "albums_assets"."assetsId" IN ($2)
-- AlbumRepository.addAssetIds
INSERT INTO
"albums_assets_assets" ("albumsId", "assetsId")
VALUES
($1, $2)
-- AlbumRepository.updateThumbnails
UPDATE "albums"
SET
"albumThumbnailAssetId" = (
SELECT
"album_assets"."assetsId"
FROM
"albums_assets_assets" "album_assets"
INNER JOIN "assets" "assets" ON "album_assets"."assetsId" = "assets"."id"
AND "assets"."deletedAt" IS NULL
WHERE
"album_assets"."albumsId" = "albums"."id"
ORDER BY
"assets"."fileCreatedAt" DESC
LIMIT
1
),
"updatedAt" = CURRENT_TIMESTAMP
WHERE
"albums"."albumThumbnailAssetId" IS NULL
AND EXISTS (
SELECT
1
FROM
"albums_assets_assets" "album_assets"
INNER JOIN "assets" "assets" ON "album_assets"."assetsId" = "assets"."id"
AND "assets"."deletedAt" IS NULL
WHERE
"album_assets"."albumsId" = "albums"."id"
)
OR "albums"."albumThumbnailAssetId" IS NOT NULL
AND NOT EXISTS (
SELECT
1
FROM
"albums_assets_assets" "album_assets"
INNER JOIN "assets" "assets" ON "album_assets"."assetsId" = "assets"."id"
AND "assets"."deletedAt" IS NULL
WHERE
"album_assets"."albumsId" = "albums"."id"
AND "albums"."albumThumbnailAssetId" = "album_assets"."assetsId"
)
+92 -11
View File
@@ -9,12 +9,16 @@ with
make_date(year::int, $1::int, $2::int) as "date"
from
generate_series(
$3,
extract(
year
(
select
date_part(
'year',
min((("localDateTime" at time zone 'UTC')::date))
)::int
from
current_date
) - 1
assets
),
date_part('year', current_date)::int - 1
) as "year"
)
select
@@ -31,20 +35,20 @@ with
where
"asset_job_status"."previewAt" is not null
and (assets."localDateTime" at time zone 'UTC')::date = today.date
and "assets"."ownerId" = any ($4::uuid [])
and "assets"."isVisible" = $5
and "assets"."isArchived" = $6
and "assets"."ownerId" = any ($3::uuid [])
and "assets"."isVisible" = $4
and "assets"."isArchived" = $5
and exists (
select
from
"asset_files"
where
"assetId" = "assets"."id"
and "asset_files"."type" = $7
and "asset_files"."type" = $6
)
and "assets"."deletedAt" is null
limit
$8
$7
) as "a" on true
inner join "exif" on "a"."id" = "exif"."assetId"
)
@@ -60,7 +64,7 @@ group by
order by
("localDateTime" at time zone 'UTC')::date desc
limit
$9
$8
-- AssetRepository.getByIds
select
@@ -208,6 +212,17 @@ where
limit
$4
-- AssetRepository.getByChecksums
select
"id",
"checksum",
"deletedAt"
from
"assets"
where
"ownerId" = $1::uuid
and "checksum" in ($2)
-- AssetRepository.getUploadAssetIdByChecksum
select
"id"
@@ -274,6 +289,52 @@ where
order by
"assets"."localDateTime" desc
-- AssetRepository.getDuplicates
with
"duplicates" as (
select
"duplicateId",
jsonb_agg("assets") as "assets"
from
"assets"
where
"ownerId" = $1::uuid
and "duplicateId" is not null
and "deletedAt" is null
and "isVisible" = $2
group by
"duplicateId"
),
"unique" as (
select
"duplicateId"
from
"duplicates"
where
jsonb_array_length("assets") = $3
),
"removed_unique" as (
update "assets"
set
"duplicateId" = $4
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 (
@@ -317,3 +378,23 @@ order by
"id" asc
limit
$5
-- AssetRepository.getChangedDeltaSync
select
"assets".*,
(
select
count(*) as "stackedAssetsCount"
from
"asset_stack"
where
"asset_stack"."id" = "assets"."stackId"
) as "stackedAssetsCount"
from
"assets"
where
"ownerId" = any ($1::uuid [])
and "isVisible" = $2
and "updatedAt" > $3
limit
$4
-14
View File
@@ -8,17 +8,3 @@ FROM
WHERE
"memories_assets"."memoriesId" = $1
AND "memories_assets"."assetsId" IN ($2)
-- MemoryRepository.addAssetIds
INSERT INTO
"memories_assets_assets" ("memoriesId", "assetsId")
VALUES
($1, $2)
-- MemoryRepository.removeAssetIds
DELETE FROM "memories_assets_assets"
WHERE
(
"memoriesId" = $1
AND "assetsId" IN ($2)
)
+69
View File
@@ -20,6 +20,47 @@ limit
offset
$7
-- SearchRepository.searchRandom
(
select
"assets".*
from
"assets"
inner join "exif" on "assets"."id" = "exif"."assetId"
where
"assets"."fileCreatedAt" >= $1
and "exif"."lensModel" = $2
and "assets"."ownerId" = any ($3::uuid [])
and "assets"."isFavorite" = $4
and "assets"."isArchived" = $5
and "assets"."deletedAt" is null
and "assets"."id" < $6
order by
"assets"."id"
limit
$7
)
union all
(
select
"assets".*
from
"assets"
inner join "exif" on "assets"."id" = "exif"."assetId"
where
"assets"."fileCreatedAt" >= $8
and "exif"."lensModel" = $9
and "assets"."ownerId" = any ($10::uuid [])
and "assets"."isFavorite" = $11
and "assets"."isArchived" = $12
and "assets"."deletedAt" is null
and "assets"."id" > $13
order by
"assets"."id"
limit
$14
)
-- SearchRepository.searchSmart
select
"assets".*
@@ -41,6 +82,34 @@ limit
offset
$8
-- SearchRepository.searchDuplicates
with
"cte" as (
select
"assets"."id" as "assetId",
"assets"."duplicateId",
smart_search.embedding <= > $1::vector as "distance"
from
"assets"
inner join "smart_search" on "assets"."id" = "smart_search"."assetId"
where
"assets"."ownerId" = any ($2::uuid [])
and "assets"."deletedAt" is null
and "assets"."isVisible" = $3
and "assets"."type" = $4
and "assets"."id" != $5::uuid
order by
smart_search.embedding <= > $6::vector
limit
$7
)
select
*
from
"cte"
where
"cte"."distance" <= $8
-- SearchRepository.searchFaces
with
"cte" as (
-20
View File
@@ -8,23 +8,3 @@ FROM
WHERE
"tag_asset"."tagsId" = $1
AND "tag_asset"."assetsId" IN ($2)
-- TagRepository.addAssetIds
INSERT INTO
"tag_asset" ("assetsId", "tagsId")
VALUES
($1, $2)
-- TagRepository.removeAssetIds
DELETE FROM "tag_asset"
WHERE
(
"tagsId" = $1
AND "assetsId" IN ($2)
)
-- TagRepository.upsertAssetIds
INSERT INTO
"tag_asset" ("assetsId", "tagsId")
VALUES
($1, $2)