mirror of
https://github.com/immich-app/immich.git
synced 2025-01-06 03:46:47 +01:00
refactor(server): library asset deletion (#4366)
This commit is contained in:
parent
c68702c0a7
commit
982dcd7b8d
1 changed files with 9 additions and 25 deletions
|
@ -139,8 +139,10 @@ export class LibraryService {
|
||||||
// TODO use pagination
|
// TODO use pagination
|
||||||
const assetIds = await this.repository.getAssetIds(job.id);
|
const assetIds = await this.repository.getAssetIds(job.id);
|
||||||
this.logger.debug(`Will delete ${assetIds.length} asset(s) in library ${job.id}`);
|
this.logger.debug(`Will delete ${assetIds.length} asset(s) in library ${job.id}`);
|
||||||
// TODO queue a job for asset deletion
|
for (const assetId of assetIds) {
|
||||||
await this.deleteAssets(assetIds);
|
await this.jobRepository.queue({ name: JobName.ASSET_DELETION, data: { id: assetId, fromExternal: true } });
|
||||||
|
}
|
||||||
|
|
||||||
this.logger.log(`Deleting library ${job.id}`);
|
this.logger.log(`Deleting library ${job.id}`);
|
||||||
await this.repository.delete(job.id);
|
await this.repository.delete(job.id);
|
||||||
return true;
|
return true;
|
||||||
|
@ -333,20 +335,17 @@ export class LibraryService {
|
||||||
}
|
}
|
||||||
|
|
||||||
async handleOfflineRemoval(job: IEntityJob): Promise<boolean> {
|
async handleOfflineRemoval(job: IEntityJob): Promise<boolean> {
|
||||||
const assetPagination = usePagination(JOBS_ASSET_PAGINATION_SIZE, (pagination) => {
|
const assetPagination = usePagination(JOBS_ASSET_PAGINATION_SIZE, (pagination) =>
|
||||||
return this.assetRepository.getWith(pagination, WithProperty.IS_OFFLINE, job.id);
|
this.assetRepository.getWith(pagination, WithProperty.IS_OFFLINE, job.id),
|
||||||
});
|
);
|
||||||
|
|
||||||
const assetIds: string[] = [];
|
|
||||||
|
|
||||||
for await (const assets of assetPagination) {
|
for await (const assets of assetPagination) {
|
||||||
|
this.logger.debug(`Removing ${assets.length} offline assets`);
|
||||||
for (const asset of 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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -439,19 +438,4 @@ export class LibraryService {
|
||||||
}
|
}
|
||||||
return library;
|
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 },
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue