From c5fb13e0d5439cc5248f0db349b8b17d59f5fb11 Mon Sep 17 00:00:00 2001 From: izzy Date: Thu, 12 Feb 2026 12:00:01 +0000 Subject: [PATCH] refactor: split refresh into private functions Signed-off-by: izzy --- server/src/services/integrity.service.ts | 100 +++++++++++++---------- 1 file changed, 55 insertions(+), 45 deletions(-) diff --git a/server/src/services/integrity.service.ts b/server/src/services/integrity.service.ts index 4978f06de2..0ba292cda8 100644 --- a/server/src/services/integrity.service.ts +++ b/server/src/services/integrity.service.ts @@ -193,8 +193,7 @@ export class IntegrityService extends BaseService { } } - @OnJob({ name: JobName.IntegrityUntrackedFilesQueueAll, queue: QueueName.IntegrityCheck }) - async handleUntrackedFilesQueueAll({ refreshOnly }: IIntegrityJob = {}): Promise { + private async queueRefreshAllUntrackedFiles() { this.logger.log(`Checking for out of date untracked file reports...`); const reports = this.integrityRepository.streamIntegrityReportsWithAssetChecksum(IntegrityReportType.UntrackedFile); @@ -211,6 +210,11 @@ export class IntegrityService extends BaseService { total += batchReports.length; this.logger.log(`Queued report check of ${batchReports.length} report(s) (${total} so far)`); } + } + + @OnJob({ name: JobName.IntegrityUntrackedFilesQueueAll, queue: QueueName.IntegrityCheck }) + async handleUntrackedFilesQueueAll({ refreshOnly }: IIntegrityJob = {}): Promise { + await this.queueRefreshAllUntrackedFiles(); if (refreshOnly) { this.logger.log('Refresh complete.'); @@ -243,7 +247,7 @@ export class IntegrityService extends BaseService { } } - total = 0; + let total = 0; for await (const [batchType, batchPaths] of paths()) { await this.jobRepository.queue({ name: JobName.IntegrityUntrackedFiles, @@ -319,27 +323,31 @@ export class IntegrityService extends BaseService { return JobStatus.Success; } + private async queueRefreshAllMissingFiles() { + this.logger.log(`Checking for out of date missing file reports...`); + + const reports = this.integrityRepository.streamIntegrityReportsWithAssetChecksum(IntegrityReportType.MissingFile); + + let total = 0; + for await (const batchReports of chunk(reports, JOBS_LIBRARY_PAGINATION_SIZE)) { + await this.jobRepository.queue({ + name: JobName.IntegrityMissingFilesRefresh, + data: { + items: batchReports, + }, + }); + + total += batchReports.length; + this.logger.log(`Queued report check of ${batchReports.length} report(s) (${total} so far)`); + } + + this.logger.log('Refresh complete.'); + } + @OnJob({ name: JobName.IntegrityMissingFilesQueueAll, queue: QueueName.IntegrityCheck }) async handleMissingFilesQueueAll({ refreshOnly }: IIntegrityJob = {}): Promise { if (refreshOnly) { - this.logger.log(`Checking for out of date missing file reports...`); - - const reports = this.integrityRepository.streamIntegrityReportsWithAssetChecksum(IntegrityReportType.MissingFile); - - let total = 0; - for await (const batchReports of chunk(reports, JOBS_LIBRARY_PAGINATION_SIZE)) { - await this.jobRepository.queue({ - name: JobName.IntegrityMissingFilesRefresh, - data: { - items: batchReports, - }, - }); - - total += batchReports.length; - this.logger.log(`Queued report check of ${batchReports.length} report(s) (${total} so far)`); - } - - this.logger.log('Refresh complete.'); + await this.queueRefreshAllMissingFiles(); return JobStatus.Success; } @@ -423,33 +431,35 @@ export class IntegrityService extends BaseService { return JobStatus.Success; } + async queueRefreshAllChecksumFiles() { + this.logger.log(`Checking for out of date checksum file reports...`); + + const reports = this.integrityRepository.streamIntegrityReportsWithAssetChecksum(IntegrityReportType.ChecksumFail); + + let total = 0; + for await (const batchReports of chunk(reports, JOBS_LIBRARY_PAGINATION_SIZE)) { + await this.jobRepository.queue({ + name: JobName.IntegrityChecksumFilesRefresh, + data: { + items: batchReports.map(({ path, reportId, checksum }) => ({ + path, + reportId, + checksum: checksum?.toString('hex'), + })), + }, + }); + + total += batchReports.length; + this.logger.log(`Queued report check of ${batchReports.length} report(s) (${total} so far)`); + } + + this.logger.log('Refresh complete.'); + } + @OnJob({ name: JobName.IntegrityChecksumFiles, queue: QueueName.IntegrityCheck }) async handleChecksumFiles({ refreshOnly }: IIntegrityJob = {}): Promise { if (refreshOnly) { - this.logger.log(`Checking for out of date checksum file reports...`); - - const reports = this.integrityRepository.streamIntegrityReportsWithAssetChecksum( - IntegrityReportType.ChecksumFail, - ); - - let total = 0; - for await (const batchReports of chunk(reports, JOBS_LIBRARY_PAGINATION_SIZE)) { - await this.jobRepository.queue({ - name: JobName.IntegrityChecksumFilesRefresh, - data: { - items: batchReports.map(({ path, reportId, checksum }) => ({ - path, - reportId, - checksum: checksum?.toString('hex'), - })), - }, - }); - - total += batchReports.length; - this.logger.log(`Queued report check of ${batchReports.length} report(s) (${total} so far)`); - } - - this.logger.log('Refresh complete.'); + await this.queueRefreshAllChecksumFiles(); return JobStatus.Success; }