High performance self-hosted photo and video management solution.
TypeScript backup-toolfluttergoogle-photosgoogle-photos-alternativejavascriptmobile-appnestjsnodejsphoto-galleryphotosphotos-managementself-hostedsveltesveltekittypescriptvideos
refactor(server): library asset deletion (#4366)
Jason Rasmussen982dcd7b8dc6
diff --git a/server/src/domain/library/library.service.ts b/server/src/domain/library/library.service.tsindex 660aec60bd..cba40275e7 100644--- a/server/src/domain/library/library.service.ts+++ b/server/src/domain/library/library.service.ts@@ -139,8 +139,10 @@ export class LibraryService {// TODO use paginationconst assetIds = await this.repository.getAssetIds(job.id);this.logger.debug(`Will delete ${assetIds.length} asset(s) in library ${job.id}`);- // TODO queue a job for asset deletion- await this.deleteAssets(assetIds);+ for (const assetId of assetIds) {+ await this.jobRepository.queue({ name: JobName.ASSET_DELETION, data: { id: assetId, fromExternal: true } });+ }+this.logger.log(`Deleting library ${job.id}`);await this.repository.delete(job.id);return true;@@ -333,20 +335,17 @@ export class LibraryService {}async handleOfflineRemoval(job: IEntityJob): Promise<boolean> {- const assetPagination = usePagination(JOBS_ASSET_PAGINATION_SIZE, (pagination) => {- return this.assetRepository.getWith(pagination, WithProperty.IS_OFFLINE, job.id);- });-- const assetIds: string[] = [];+ const assetPagination = usePagination(JOBS_ASSET_PAGINATION_SIZE, (pagination) =>+ this.assetRepository.getWith(pagination, WithProperty.IS_OFFLINE, job.id),+ );for await (const assets of assetPagination) {+ this.logger.debug(`Removing ${assets.length} offline assets`);for (const asset of assets) {- assetIds.push(asset.id);+ await this.jobRepository.queue({ name: JobName.ASSET_DELETION, data: { id: asset.id, fromExternal: true } });}}- this.logger.verbose(`Found ${assetIds.length} offline assets to remove`);- await this.deleteAssets(assetIds);return true;}@@ -439,19 +438,4 @@ export class LibraryService {}return library;}-- private async deleteAssets(assetIds: string[]) {- for (const assetId of assetIds) {- const asset = await this.assetRepository.getById(assetId);- if (!asset) {- continue;- }- this.logger.debug(`Removing asset from library: ${asset.originalPath}`);-- await this.jobRepository.queue({- name: JobName.ASSET_DELETION,- data: { id: asset.id, fromExternal: true },- });- }- }}