From 502854cee14733a5dc284d490907c6b97dc4c717 Mon Sep 17 00:00:00 2001 From: shenlong <139912620+shenlong-tanwen@users.noreply.github.com> Date: Wed, 2 Apr 2025 03:50:43 +0530 Subject: [PATCH] fix(server): remove stacks on stack.deleteAll (#17288) * fix(server): delete all stacks on deleteAll * remove unnecessary assets update * generate sql --------- Co-authored-by: shenlong-tanwen <139912620+shalong-tanwen@users.noreply.github.com> --- server/src/queries/stack.repository.sql | 42 +-------------------- server/src/repositories/stack.repository.ts | 29 +------------- 2 files changed, 2 insertions(+), 69 deletions(-) diff --git a/server/src/queries/stack.repository.sql b/server/src/queries/stack.repository.sql index 0fd1b233be..9fff558192 100644 --- a/server/src/queries/stack.repository.sql +++ b/server/src/queries/stack.repository.sql @@ -32,47 +32,7 @@ where "asset_stack"."ownerId" = $1 -- StackRepository.delete -select - *, - ( - select - coalesce(json_agg(agg), '[]') - from - ( - select - "assets".*, - ( - select - coalesce(json_agg(agg), '[]') - from - ( - select - "tags".* - from - "tags" - inner join "tag_asset" on "tags"."id" = "tag_asset"."tagsId" - where - "tag_asset"."assetsId" = "assets"."id" - ) as agg - ) as "tags", - to_json("exifInfo") as "exifInfo" - from - "assets" - inner join lateral ( - select - "exif".* - from - "exif" - where - "exif"."assetId" = "assets"."id" - ) as "exifInfo" on true - where - "assets"."deletedAt" is null - and "assets"."stackId" = "asset_stack"."id" - ) as agg - ) as "assets" -from - "asset_stack" +delete from "asset_stack" where "id" = $1::uuid diff --git a/server/src/repositories/stack.repository.ts b/server/src/repositories/stack.repository.ts index ae96005350..501067072d 100644 --- a/server/src/repositories/stack.repository.ts +++ b/server/src/repositories/stack.repository.ts @@ -122,38 +122,11 @@ export class StackRepository { @GenerateSql({ params: [DummyValue.UUID] }) async delete(id: string): Promise { - const stack = await this.getById(id); - if (!stack) { - return; - } - - const assetIds = stack.assets.map(({ id }) => id); - await this.db.deleteFrom('asset_stack').where('id', '=', asUuid(id)).execute(); - await this.db - .updateTable('assets') - .set({ stackId: null, updatedAt: new Date() }) - .where('id', 'in', assetIds) - .execute(); } async deleteAll(ids: string[]): Promise { - const assetIds = []; - for (const id of ids) { - const stack = await this.getById(id); - if (!stack) { - continue; - } - - assetIds.push(...stack.assets.map(({ id }) => id)); - } - - await this.db - .updateTable('assets') - .set({ updatedAt: new Date(), stackId: null }) - .where('id', 'in', assetIds) - .where('stackId', 'in', ids) - .execute(); + await this.db.deleteFrom('asset_stack').where('id', 'in', ids).execute(); } update(id: string, entity: Updateable): Promise {