diff options
| author | keito <131662659+mst-mkt@users.noreply.github.com> | 2025-06-25 20:30:17 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-06-25 20:30:17 +0900 |
| commit | c424554d4a9f49560e4f3d379a93c64bdabab29e (patch) | |
| tree | 009dd8a88921cd70aeb3374123da3c95dcdbba5c | |
| parent | enhance(frontend): ページネーションの並び順を逆にできるよ... (diff) | |
| download | misskey-c424554d4a9f49560e4f3d379a93c64bdabab29e.tar.gz misskey-c424554d4a9f49560e4f3d379a93c64bdabab29e.tar.bz2 misskey-c424554d4a9f49560e4f3d379a93c64bdabab29e.zip | |
ジョブキューの`Progress`の値を正しく計算する (#16218)
* fix: ジョブキューのProgressの値の範囲を 0~100 に統一
* fix(backend): ジョブキューのProgressの計算に用いる総数を最初に一度だけ取得する
8 files changed, 36 insertions, 34 deletions
diff --git a/packages/backend/src/queue/processors/CleanRemoteFilesProcessorService.ts b/packages/backend/src/queue/processors/CleanRemoteFilesProcessorService.ts index 728fc9e72b..782b74f0cd 100644 --- a/packages/backend/src/queue/processors/CleanRemoteFilesProcessorService.ts +++ b/packages/backend/src/queue/processors/CleanRemoteFilesProcessorService.ts @@ -34,6 +34,11 @@ export class CleanRemoteFilesProcessorService { let deletedCount = 0; let cursor: MiDriveFile['id'] | null = null; + const total = await this.driveFilesRepository.countBy({ + userHost: Not(IsNull()), + isLink: false, + }); + while (true) { const files = await this.driveFilesRepository.find({ where: { @@ -58,12 +63,7 @@ export class CleanRemoteFilesProcessorService { deletedCount += 8; - const total = await this.driveFilesRepository.countBy({ - userHost: Not(IsNull()), - isLink: false, - }); - - job.updateProgress(100 / total * deletedCount); + job.updateProgress(deletedCount * total / 100); } this.logger.succ('All cached remote files has been deleted.'); diff --git a/packages/backend/src/queue/processors/DeleteDriveFilesProcessorService.ts b/packages/backend/src/queue/processors/DeleteDriveFilesProcessorService.ts index 291fa4a6d8..5a8a8ca940 100644 --- a/packages/backend/src/queue/processors/DeleteDriveFilesProcessorService.ts +++ b/packages/backend/src/queue/processors/DeleteDriveFilesProcessorService.ts @@ -43,6 +43,10 @@ export class DeleteDriveFilesProcessorService { let deletedCount = 0; let cursor: MiDriveFile['id'] | null = null; + const total = await this.driveFilesRepository.countBy({ + userId: user.id, + }); + while (true) { const files = await this.driveFilesRepository.find({ where: { @@ -67,11 +71,7 @@ export class DeleteDriveFilesProcessorService { deletedCount++; } - const total = await this.driveFilesRepository.countBy({ - userId: user.id, - }); - - job.updateProgress(deletedCount / total); + job.updateProgress(deletedCount / total * 100); } this.logger.succ(`All drive files (${deletedCount}) of ${user.id} has been deleted.`); diff --git a/packages/backend/src/queue/processors/ExportBlockingProcessorService.ts b/packages/backend/src/queue/processors/ExportBlockingProcessorService.ts index ecc439db69..cca7cdf9da 100644 --- a/packages/backend/src/queue/processors/ExportBlockingProcessorService.ts +++ b/packages/backend/src/queue/processors/ExportBlockingProcessorService.ts @@ -58,6 +58,10 @@ export class ExportBlockingProcessorService { let exportedCount = 0; let cursor: MiBlocking['id'] | null = null; + const total = await this.blockingsRepository.countBy({ + blockerId: user.id, + }); + while (true) { const blockings = await this.blockingsRepository.find({ where: { @@ -97,11 +101,7 @@ export class ExportBlockingProcessorService { exportedCount++; } - const total = await this.blockingsRepository.countBy({ - blockerId: user.id, - }); - - job.updateProgress(exportedCount / total); + job.updateProgress(exportedCount / total * 100); } stream.end(); diff --git a/packages/backend/src/queue/processors/ExportClipsProcessorService.ts b/packages/backend/src/queue/processors/ExportClipsProcessorService.ts index 583ddbb745..486dc4c01f 100644 --- a/packages/backend/src/queue/processors/ExportClipsProcessorService.ts +++ b/packages/backend/src/queue/processors/ExportClipsProcessorService.ts @@ -95,6 +95,10 @@ export class ExportClipsProcessorService { let exportedClipsCount = 0; let cursor: MiClip['id'] | null = null; + const total = await this.clipsRepository.countBy({ + userId: user.id, + }); + while (true) { const clips = await this.clipsRepository.find({ where: { @@ -126,11 +130,7 @@ export class ExportClipsProcessorService { exportedClipsCount++; } - const total = await this.clipsRepository.countBy({ - userId: user.id, - }); - - job.updateProgress(exportedClipsCount / total); + job.updateProgress(exportedClipsCount / total * 100); } } diff --git a/packages/backend/src/queue/processors/ExportFavoritesProcessorService.ts b/packages/backend/src/queue/processors/ExportFavoritesProcessorService.ts index b81feece01..7918c8ccb5 100644 --- a/packages/backend/src/queue/processors/ExportFavoritesProcessorService.ts +++ b/packages/backend/src/queue/processors/ExportFavoritesProcessorService.ts @@ -78,6 +78,10 @@ export class ExportFavoritesProcessorService { let exportedFavoritesCount = 0; let cursor: MiNoteFavorite['id'] | null = null; + const total = await this.noteFavoritesRepository.countBy({ + userId: user.id, + }); + while (true) { const favorites = await this.noteFavoritesRepository.find({ where: { @@ -109,11 +113,7 @@ export class ExportFavoritesProcessorService { exportedFavoritesCount++; } - const total = await this.noteFavoritesRepository.countBy({ - userId: user.id, - }); - - job.updateProgress(exportedFavoritesCount / total); + job.updateProgress(exportedFavoritesCount / total * 100); } await write(']'); diff --git a/packages/backend/src/queue/processors/ExportMutingProcessorService.ts b/packages/backend/src/queue/processors/ExportMutingProcessorService.ts index f9867ade29..59448ccd34 100644 --- a/packages/backend/src/queue/processors/ExportMutingProcessorService.ts +++ b/packages/backend/src/queue/processors/ExportMutingProcessorService.ts @@ -58,6 +58,10 @@ export class ExportMutingProcessorService { let exportedCount = 0; let cursor: MiMuting['id'] | null = null; + const total = await this.mutingsRepository.countBy({ + muterId: user.id, + }); + while (true) { const mutes = await this.mutingsRepository.find({ where: { @@ -98,11 +102,7 @@ export class ExportMutingProcessorService { exportedCount++; } - const total = await this.mutingsRepository.countBy({ - muterId: user.id, - }); - - job.updateProgress(exportedCount / total); + job.updateProgress(exportedCount / total * 100); } stream.end(); diff --git a/packages/backend/src/queue/processors/ExportNotesProcessorService.ts b/packages/backend/src/queue/processors/ExportNotesProcessorService.ts index 9e2b678219..3b68a4277a 100644 --- a/packages/backend/src/queue/processors/ExportNotesProcessorService.ts +++ b/packages/backend/src/queue/processors/ExportNotesProcessorService.ts @@ -37,6 +37,8 @@ class NoteStream extends ReadableStream<Record<string, unknown>> { let exportedNotesCount = 0; let cursor: MiNote['id'] | null = null; + const totalPromise = notesRepository.countBy({ userId }); + const serialize = ( note: MiNote, poll: MiPoll | null, @@ -88,8 +90,8 @@ class NoteStream extends ReadableStream<Record<string, unknown>> { exportedNotesCount++; } - const total = await notesRepository.countBy({ userId }); - job.updateProgress(exportedNotesCount / total); + const total = await totalPromise; + job.updateProgress(exportedNotesCount / total * 100); }, }); } diff --git a/packages/frontend/src/pages/admin/job-queue.job.vue b/packages/frontend/src/pages/admin/job-queue.job.vue index 7d8cdde8b9..fb8994a10e 100644 --- a/packages/frontend/src/pages/admin/job-queue.job.vue +++ b/packages/frontend/src/pages/admin/job-queue.job.vue @@ -12,7 +12,7 @@ SPDX-License-Identifier: AGPL-3.0-only </template> <template #suffix> <MkTime :time="job.finishedOn ?? job.processedOn ?? job.timestamp" mode="relative"/> - <span v-if="job.progress != null && typeof job.progress === 'number' && job.progress > 0" style="margin-left: 1em;">{{ Math.floor(job.progress * 100) }}%</span> + <span v-if="job.progress != null && typeof job.progress === 'number' && job.progress > 0" style="margin-left: 1em;">{{ Math.floor(job.progress) }}%</span> <span v-if="job.opts.attempts != null && job.opts.attempts > 0 && job.attempts > 1" style="margin-left: 1em; color: var(--MI_THEME-warn); font-variant-numeric: diagonal-fractions;">{{ job.attempts }}/{{ job.opts.attempts }}</span> <span v-if="job.isFailed && job.finishedOn != null" style="margin-left: 1em; color: var(--MI_THEME-error)"><i class="ti ti-circle-x"></i></span> <span v-else-if="job.isFailed" style="margin-left: 1em; color: var(--MI_THEME-warn)"><i class="ti ti-alert-triangle"></i></span> |