From e2663078453e74ed7c9b467cb9a56cfc78c0e004 Mon Sep 17 00:00:00 2001 From: Jonathan Jogenfors Date: Thu, 16 Jan 2025 23:49:18 +0100 Subject: [PATCH] feat: hide assets when deleting library --- server/src/interfaces/asset.interface.ts | 1 + server/src/repositories/asset.repository.ts | 4 ++++ server/src/services/library.service.ts | 3 +++ 3 files changed, 8 insertions(+) diff --git a/server/src/interfaces/asset.interface.ts b/server/src/interfaces/asset.interface.ts index f6254fc850a63..2502cb6f4b3a3 100644 --- a/server/src/interfaces/asset.interface.ts +++ b/server/src/interfaces/asset.interface.ts @@ -155,6 +155,7 @@ export interface IAssetRepository { getAllByDeviceId(userId: string, deviceId: string): Promise; getLivePhotoCount(motionId: string): Promise; updateAll(ids: string[], options: Updateable): Promise; + updateByLibraryId(libraryId: string, options: Updateable): Promise; updateDuplicates(options: AssetUpdateDuplicateOptions): Promise; update(asset: Updateable & { id: string }): Promise; remove(asset: AssetEntity): Promise; diff --git a/server/src/repositories/asset.repository.ts b/server/src/repositories/asset.repository.ts index e7f418dcc3f94..b7c0d13aa73f4 100644 --- a/server/src/repositories/asset.repository.ts +++ b/server/src/repositories/asset.repository.ts @@ -317,6 +317,10 @@ export class AssetRepository implements IAssetRepository { await this.db.updateTable('assets').set(options).where('id', '=', anyUuid(ids)).execute(); } + async updateByLibraryId(libraryId: string, options: Updateable): Promise { + await this.db.updateTable('assets').set(options).where('libraryId', '=', asUuid(libraryId)).execute(); + } + @GenerateSql({ params: [{ targetDuplicateId: DummyValue.UUID, duplicateIds: [DummyValue.UUID], assetIds: [DummyValue.UUID] }], }) diff --git a/server/src/services/library.service.ts b/server/src/services/library.service.ts index 51ff118f8f2bc..364edb7c2e924 100644 --- a/server/src/services/library.service.ts +++ b/server/src/services/library.service.ts @@ -335,6 +335,9 @@ export class LibraryService extends BaseService { async handleDeleteLibrary(job: JobOf): Promise { const libraryId = job.id; + // Hide all assets in the library before deleting them + await this.assetRepository.updateByLibraryId(libraryId, { isVisible: false }); + const assetPagination = usePagination(JOBS_LIBRARY_PAGINATION_SIZE, (pagination) => this.assetRepository.getAll(pagination, { libraryId, withDeleted: true }), );