mirror of
https://github.com/immich-app/immich.git
synced 2025-05-24 01:12:58 -04:00
chore: no sql generation for queries with side effects (#18301)
no sql generation for queries with side effects
This commit is contained in:
parent
6a4d21205f
commit
709a7b70aa
@ -432,3 +432,34 @@ where
|
||||
and "assets"."updatedAt" > $3
|
||||
limit
|
||||
$4
|
||||
|
||||
-- AssetRepository.detectOfflineExternalAssets
|
||||
update "assets"
|
||||
set
|
||||
"isOffline" = $1,
|
||||
"deletedAt" = $2
|
||||
where
|
||||
"isOffline" = $3
|
||||
and "isExternal" = $4
|
||||
and "libraryId" = $5::uuid
|
||||
and (
|
||||
not "originalPath" like $6
|
||||
or "originalPath" like $7
|
||||
)
|
||||
|
||||
-- AssetRepository.filterNewExternalAssetPaths
|
||||
select
|
||||
"path"
|
||||
from
|
||||
unnest(array[$1]::text[]) as "path"
|
||||
where
|
||||
not exists (
|
||||
select
|
||||
"originalPath"
|
||||
from
|
||||
"assets"
|
||||
where
|
||||
"assets"."originalPath" = "path"
|
||||
and "libraryId" = $2::uuid
|
||||
and "isExternal" = $3
|
||||
)
|
||||
|
@ -14,8 +14,3 @@ order by
|
||||
"audit"."entityId" desc,
|
||||
"audit"."entityType" desc,
|
||||
"audit"."createdAt" desc
|
||||
|
||||
-- AuditRepository.removeBefore
|
||||
delete from "audit"
|
||||
where
|
||||
"createdAt" < $1
|
||||
|
@ -1,11 +1,5 @@
|
||||
-- NOTE: This file is auto generated by ./sql-generator
|
||||
|
||||
-- MemoryRepository.cleanup
|
||||
delete from "memories"
|
||||
where
|
||||
"createdAt" < $1
|
||||
and "isSaved" = $2
|
||||
|
||||
-- MemoryRepository.search
|
||||
select
|
||||
"memories".*,
|
||||
|
@ -16,19 +16,6 @@ where
|
||||
returning
|
||||
*
|
||||
|
||||
-- MoveRepository.cleanMoveHistory
|
||||
delete from "move_history"
|
||||
where
|
||||
"move_history"."entityId" not in (
|
||||
select
|
||||
"id"
|
||||
from
|
||||
"assets"
|
||||
where
|
||||
"assets"."id" = "move_history"."entityId"
|
||||
)
|
||||
and "move_history"."pathType" = 'original'
|
||||
|
||||
-- MoveRepository.cleanMoveHistorySingle
|
||||
delete from "move_history"
|
||||
where
|
||||
|
@ -1,23 +1,5 @@
|
||||
-- NOTE: This file is auto generated by ./sql-generator
|
||||
|
||||
-- NotificationRepository.cleanup
|
||||
delete from "notifications"
|
||||
where
|
||||
(
|
||||
(
|
||||
"deletedAt" is not null
|
||||
and "deletedAt" < $1
|
||||
)
|
||||
or (
|
||||
"readAt" > $2
|
||||
and "createdAt" < $3
|
||||
)
|
||||
or (
|
||||
"readAt" = $4
|
||||
and "createdAt" < $5
|
||||
)
|
||||
)
|
||||
|
||||
-- NotificationRepository.search
|
||||
select
|
||||
"id",
|
||||
|
@ -100,50 +100,6 @@ where
|
||||
"sharedWithId" = $1
|
||||
and "sharedById" = $2
|
||||
|
||||
-- PartnerRepository.create
|
||||
insert into
|
||||
"partners" ("sharedWithId", "sharedById")
|
||||
values
|
||||
($1, $2)
|
||||
returning
|
||||
*,
|
||||
(
|
||||
select
|
||||
to_json(obj)
|
||||
from
|
||||
(
|
||||
select
|
||||
"id",
|
||||
"name",
|
||||
"email",
|
||||
"avatarColor",
|
||||
"profileImagePath",
|
||||
"profileChangedAt"
|
||||
from
|
||||
"users" as "sharedBy"
|
||||
where
|
||||
"sharedBy"."id" = "partners"."sharedById"
|
||||
) as obj
|
||||
) as "sharedBy",
|
||||
(
|
||||
select
|
||||
to_json(obj)
|
||||
from
|
||||
(
|
||||
select
|
||||
"id",
|
||||
"name",
|
||||
"email",
|
||||
"avatarColor",
|
||||
"profileImagePath",
|
||||
"profileChangedAt"
|
||||
from
|
||||
"users" as "sharedWith"
|
||||
where
|
||||
"sharedWith"."id" = "partners"."sharedWithId"
|
||||
) as obj
|
||||
) as "sharedWith"
|
||||
|
||||
-- PartnerRepository.update
|
||||
update "partners"
|
||||
set
|
||||
|
@ -7,22 +7,10 @@ set
|
||||
where
|
||||
"asset_faces"."personId" = $2
|
||||
|
||||
-- PersonRepository.unassignFaces
|
||||
update "asset_faces"
|
||||
set
|
||||
"personId" = $1
|
||||
where
|
||||
"asset_faces"."sourceType" = $2
|
||||
|
||||
-- PersonRepository.delete
|
||||
delete from "person"
|
||||
where
|
||||
"person"."id" in $1
|
||||
|
||||
-- PersonRepository.deleteFaces
|
||||
delete from "asset_faces"
|
||||
where
|
||||
"asset_faces"."sourceType" = $1
|
||||
"person"."id" in ($1)
|
||||
|
||||
-- PersonRepository.getAllWithoutFaces
|
||||
select
|
||||
@ -216,21 +204,6 @@ where
|
||||
"person"."ownerId" = $3
|
||||
and "asset_faces"."deletedAt" is null
|
||||
|
||||
-- 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_faces".*,
|
||||
|
@ -8,15 +8,6 @@ from
|
||||
where
|
||||
"key" = $1
|
||||
|
||||
-- SystemMetadataRepository.set
|
||||
insert into
|
||||
"system_metadata" ("key", "value")
|
||||
values
|
||||
($1, $2)
|
||||
on conflict ("key") do update
|
||||
set
|
||||
"value" = $3
|
||||
|
||||
-- SystemMetadataRepository.delete
|
||||
delete from "system_metadata"
|
||||
where
|
||||
|
@ -58,7 +58,7 @@ from
|
||||
where
|
||||
"userId" = $1
|
||||
order by
|
||||
"value" asc
|
||||
"value"
|
||||
|
||||
-- TagRepository.create
|
||||
insert into
|
||||
@ -94,6 +94,15 @@ where
|
||||
"tagsId" = $1
|
||||
and "assetsId" in ($2)
|
||||
|
||||
-- TagRepository.upsertAssetIds
|
||||
insert into
|
||||
"tag_asset" ("assetId", "tagsIds")
|
||||
values
|
||||
($1, $2)
|
||||
on conflict do nothing
|
||||
returning
|
||||
*
|
||||
|
||||
-- TagRepository.replaceAssetTags
|
||||
begin
|
||||
delete from "tag_asset"
|
||||
@ -107,17 +116,3 @@ on conflict do nothing
|
||||
returning
|
||||
*
|
||||
rollback
|
||||
|
||||
-- TagRepository.deleteEmptyTags
|
||||
begin
|
||||
select
|
||||
"tags"."id",
|
||||
count("assets"."id") as "count"
|
||||
from
|
||||
"assets"
|
||||
inner join "tag_asset" on "tag_asset"."assetsId" = "assets"."id"
|
||||
inner join "tags_closure" on "tags_closure"."id_descendant" = "tag_asset"."tagsId"
|
||||
inner join "tags" on "tags"."id" = "tags_closure"."id_descendant"
|
||||
group by
|
||||
"tags"."id"
|
||||
commit
|
||||
|
@ -15,11 +15,3 @@ from
|
||||
"version_history"
|
||||
order by
|
||||
"createdAt" desc
|
||||
|
||||
-- VersionHistoryRepository.create
|
||||
insert into
|
||||
"version_history" ("version")
|
||||
values
|
||||
($1)
|
||||
returning
|
||||
*
|
||||
|
@ -817,9 +817,7 @@ export class AssetRepository {
|
||||
.execute();
|
||||
}
|
||||
|
||||
@GenerateSql({
|
||||
params: [{ libraryId: DummyValue.UUID, importPaths: [DummyValue.STRING], exclusionPatterns: [DummyValue.STRING] }],
|
||||
})
|
||||
@GenerateSql({ params: [DummyValue.UUID, [DummyValue.STRING], [DummyValue.STRING]] })
|
||||
async detectOfflineExternalAssets(
|
||||
libraryId: string,
|
||||
importPaths: string[],
|
||||
@ -846,9 +844,7 @@ export class AssetRepository {
|
||||
.executeTakeFirstOrThrow();
|
||||
}
|
||||
|
||||
@GenerateSql({
|
||||
params: [{ libraryId: DummyValue.UUID, paths: [DummyValue.STRING] }],
|
||||
})
|
||||
@GenerateSql({ params: [DummyValue.UUID, [DummyValue.STRING]] })
|
||||
async filterNewExternalAssetPaths(libraryId: string, paths: string[]): Promise<string[]> {
|
||||
const result = await this.db
|
||||
.selectFrom(unnest(paths).as('path'))
|
||||
|
@ -38,7 +38,6 @@ export class AuditRepository {
|
||||
return records.map(({ entityId }) => entityId);
|
||||
}
|
||||
|
||||
@GenerateSql({ params: [DummyValue.DATE] })
|
||||
async removeBefore(before: Date): Promise<void> {
|
||||
await this.db.deleteFrom('audit').where('createdAt', '<', before).execute();
|
||||
}
|
||||
|
@ -12,7 +12,6 @@ import { IBulkAsset } from 'src/types';
|
||||
export class MemoryRepository implements IBulkAsset {
|
||||
constructor(@InjectKysely() private db: Kysely<DB>) {}
|
||||
|
||||
@GenerateSql({ params: [DummyValue.UUID] })
|
||||
cleanup() {
|
||||
return this.db
|
||||
.deleteFrom('memories')
|
||||
|
@ -37,7 +37,6 @@ export class MoveRepository {
|
||||
return this.db.deleteFrom('move_history').where('id', '=', id).returningAll().executeTakeFirstOrThrow();
|
||||
}
|
||||
|
||||
@GenerateSql()
|
||||
async cleanMoveHistory(): Promise<void> {
|
||||
await this.db
|
||||
.deleteFrom('move_history')
|
||||
@ -52,7 +51,7 @@ export class MoveRepository {
|
||||
.execute();
|
||||
}
|
||||
|
||||
@GenerateSql()
|
||||
@GenerateSql({ params: [DummyValue.UUID] })
|
||||
async cleanMoveHistorySingle(assetId: string): Promise<void> {
|
||||
await this.db
|
||||
.deleteFrom('move_history')
|
||||
|
@ -9,7 +9,6 @@ import { NotificationSearchDto } from 'src/dtos/notification.dto';
|
||||
export class NotificationRepository {
|
||||
constructor(@InjectKysely() private db: Kysely<DB>) {}
|
||||
|
||||
@GenerateSql({ params: [DummyValue.UUID] })
|
||||
cleanup() {
|
||||
return this.db
|
||||
.deleteFrom('notifications')
|
||||
|
@ -47,7 +47,6 @@ export class PartnerRepository {
|
||||
.executeTakeFirst();
|
||||
}
|
||||
|
||||
@GenerateSql({ params: [{ sharedWithId: DummyValue.UUID, sharedById: DummyValue.UUID }] })
|
||||
create(values: Insertable<Partners>) {
|
||||
return this.db
|
||||
.insertInto('partners')
|
||||
|
@ -98,7 +98,6 @@ export class PersonRepository {
|
||||
return Number(result.numChangedRows ?? 0);
|
||||
}
|
||||
|
||||
@GenerateSql({ params: [{ sourceType: SourceType.EXIF }] })
|
||||
async unassignFaces({ sourceType }: UnassignFacesOptions): Promise<void> {
|
||||
await this.db
|
||||
.updateTable('asset_faces')
|
||||
@ -107,7 +106,7 @@ export class PersonRepository {
|
||||
.execute();
|
||||
}
|
||||
|
||||
@GenerateSql({ params: [DummyValue.UUID] })
|
||||
@GenerateSql({ params: [[DummyValue.UUID]] })
|
||||
async delete(ids: string[]): Promise<void> {
|
||||
if (ids.length === 0) {
|
||||
return;
|
||||
@ -116,7 +115,6 @@ export class PersonRepository {
|
||||
await this.db.deleteFrom('person').where('person.id', 'in', ids).execute();
|
||||
}
|
||||
|
||||
@GenerateSql({ params: [{ sourceType: SourceType.EXIF }] })
|
||||
async deleteFaces({ sourceType }: DeleteFacesOptions): Promise<void> {
|
||||
await this.db.deleteFrom('asset_faces').where('asset_faces.sourceType', '=', sourceType).execute();
|
||||
}
|
||||
@ -400,7 +398,6 @@ export class PersonRepository {
|
||||
return results.map(({ id }) => id);
|
||||
}
|
||||
|
||||
@GenerateSql({ params: [[], [], [{ faceId: DummyValue.UUID, embedding: DummyValue.VECTOR }]] })
|
||||
async refreshFaces(
|
||||
facesToAdd: (Insertable<AssetFaces> & { assetId: string })[],
|
||||
faceIdsToRemove: string[],
|
||||
|
@ -26,7 +26,6 @@ export class SystemMetadataRepository {
|
||||
return metadata.value as SystemMetadata[T];
|
||||
}
|
||||
|
||||
@GenerateSql({ params: ['metadata_key', { foo: 'bar' }] })
|
||||
async set<T extends keyof SystemMetadata>(key: T, value: SystemMetadata[T]): Promise<void> {
|
||||
await this.db
|
||||
.insertInto('system_metadata')
|
||||
|
@ -68,7 +68,7 @@ export class TagRepository {
|
||||
|
||||
@GenerateSql({ params: [DummyValue.UUID] })
|
||||
getAll(userId: string) {
|
||||
return this.db.selectFrom('tags').select(columns.tag).where('userId', '=', userId).orderBy('value asc').execute();
|
||||
return this.db.selectFrom('tags').select(columns.tag).where('userId', '=', userId).orderBy('value').execute();
|
||||
}
|
||||
|
||||
@GenerateSql({ params: [{ userId: DummyValue.UUID, color: DummyValue.STRING, value: DummyValue.STRING }] })
|
||||
@ -126,7 +126,7 @@ export class TagRepository {
|
||||
await this.db.deleteFrom('tag_asset').where('tagsId', '=', tagId).where('assetsId', 'in', assetIds).execute();
|
||||
}
|
||||
|
||||
@GenerateSql({ params: [{ assetId: DummyValue.UUID, tagsIds: [DummyValue.UUID] }] })
|
||||
@GenerateSql({ params: [[{ assetId: DummyValue.UUID, tagsIds: [DummyValue.UUID] }]] })
|
||||
@Chunked()
|
||||
upsertAssetIds(items: Insertable<TagAsset>[]) {
|
||||
if (items.length === 0) {
|
||||
@ -160,7 +160,6 @@ export class TagRepository {
|
||||
});
|
||||
}
|
||||
|
||||
@GenerateSql()
|
||||
async deleteEmptyTags() {
|
||||
// TODO rewrite as a single statement
|
||||
await this.db.transaction().execute(async (tx) => {
|
||||
|
@ -18,7 +18,6 @@ export class VersionHistoryRepository {
|
||||
return this.db.selectFrom('version_history').selectAll().orderBy('createdAt', 'desc').executeTakeFirst();
|
||||
}
|
||||
|
||||
@GenerateSql({ params: [{ version: 'v1.123.0' }] })
|
||||
create(version: Insertable<VersionHistory>) {
|
||||
return this.db.insertInto('version_history').values(version).returningAll().executeTakeFirstOrThrow();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user