feat(server): library cleanup from ui (#16226)

* feat(server,web): scan all libraries from frontend

* feat(server,web): scan all libraries from frontend

* Add button text
This commit is contained in:
Jonathan Jogenfors
2025-03-03 04:29:02 +01:00
committed by GitHub
parent 8885e3105e
commit 869839f642
11 changed files with 37 additions and 24 deletions
+1 -1
View File
@@ -170,7 +170,7 @@ export class JobService extends BaseService {
}
case QueueName.LIBRARY: {
return this.jobRepository.queue({ name: JobName.LIBRARY_QUEUE_SYNC_ALL, data: { force } });
return this.jobRepository.queue({ name: JobName.LIBRARY_QUEUE_SCAN_ALL, data: { force } });
}
case QueueName.BACKUP_DATABASE: {
+1 -1
View File
@@ -1079,7 +1079,7 @@ describe(LibraryService.name, () => {
it('should queue the refresh job', async () => {
mocks.library.getAll.mockResolvedValue([libraryStub.externalLibrary1]);
await expect(sut.handleQueueSyncAll()).resolves.toBe(JobStatus.SUCCESS);
await expect(sut.handleQueueScanAll()).resolves.toBe(JobStatus.SUCCESS);
expect(mocks.job.queue.mock.calls).toEqual([
[
+19 -9
View File
@@ -47,7 +47,7 @@ export class LibraryService extends BaseService {
name: 'libraryScan',
expression: scan.cronExpression,
onTick: () =>
handlePromiseError(this.jobRepository.queue({ name: JobName.LIBRARY_QUEUE_SYNC_ALL }), this.logger),
handlePromiseError(this.jobRepository.queue({ name: JobName.LIBRARY_QUEUE_SCAN_ALL }), this.logger),
start: scan.enabled,
});
}
@@ -210,11 +210,17 @@ export class LibraryService extends BaseService {
@OnJob({ name: JobName.LIBRARY_QUEUE_CLEANUP, queue: QueueName.LIBRARY })
async handleQueueCleanup(): Promise<JobStatus> {
this.logger.debug('Cleaning up any pending library deletions');
const pendingDeletion = await this.libraryRepository.getAllDeleted();
await this.jobRepository.queueAll(
pendingDeletion.map((libraryToDelete) => ({ name: JobName.LIBRARY_DELETE, data: { id: libraryToDelete.id } })),
);
this.logger.log('Checking for any libraries pending deletion...');
const pendingDeletions = await this.libraryRepository.getAllDeleted();
if (pendingDeletions.length > 0) {
const libraryString = pendingDeletions.length === 1 ? 'library' : 'libraries';
this.logger.log(`Found ${pendingDeletions.length} ${libraryString} pending deletion, cleaning up...`);
await this.jobRepository.queueAll(
pendingDeletions.map((libraryToDelete) => ({ name: JobName.LIBRARY_DELETE, data: { id: libraryToDelete.id } })),
);
}
return JobStatus.SUCCESS;
}
@@ -442,9 +448,13 @@ export class LibraryService extends BaseService {
await this.jobRepository.queue({ name: JobName.LIBRARY_QUEUE_SYNC_ASSETS, data: { id } });
}
@OnJob({ name: JobName.LIBRARY_QUEUE_SYNC_ALL, queue: QueueName.LIBRARY })
async handleQueueSyncAll(): Promise<JobStatus> {
this.logger.debug(`Refreshing all external libraries`);
async queueScanAll() {
await this.jobRepository.queue({ name: JobName.LIBRARY_QUEUE_SCAN_ALL, data: {} });
}
@OnJob({ name: JobName.LIBRARY_QUEUE_SCAN_ALL, queue: QueueName.LIBRARY })
async handleQueueScanAll(): Promise<JobStatus> {
this.logger.log(`Refreshing all external libraries`);
await this.jobRepository.queue({ name: JobName.LIBRARY_QUEUE_CLEANUP, data: {} });