ジョブキューの`Progress`の値を正しく計算する (#16218)
* fix: ジョブキューのProgressの値の範囲を 0~100 に統一 * fix(backend): ジョブキューのProgressの計算に用いる総数を最初に一度だけ取得する
This commit is contained in:
parent
eee9a5f853
commit
c424554d4a
|
@ -34,6 +34,11 @@ export class CleanRemoteFilesProcessorService {
|
||||||
let deletedCount = 0;
|
let deletedCount = 0;
|
||||||
let cursor: MiDriveFile['id'] | null = null;
|
let cursor: MiDriveFile['id'] | null = null;
|
||||||
|
|
||||||
|
const total = await this.driveFilesRepository.countBy({
|
||||||
|
userHost: Not(IsNull()),
|
||||||
|
isLink: false,
|
||||||
|
});
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
const files = await this.driveFilesRepository.find({
|
const files = await this.driveFilesRepository.find({
|
||||||
where: {
|
where: {
|
||||||
|
@ -58,12 +63,7 @@ export class CleanRemoteFilesProcessorService {
|
||||||
|
|
||||||
deletedCount += 8;
|
deletedCount += 8;
|
||||||
|
|
||||||
const total = await this.driveFilesRepository.countBy({
|
job.updateProgress(deletedCount * total / 100);
|
||||||
userHost: Not(IsNull()),
|
|
||||||
isLink: false,
|
|
||||||
});
|
|
||||||
|
|
||||||
job.updateProgress(100 / total * deletedCount);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.logger.succ('All cached remote files has been deleted.');
|
this.logger.succ('All cached remote files has been deleted.');
|
||||||
|
|
|
@ -43,6 +43,10 @@ export class DeleteDriveFilesProcessorService {
|
||||||
let deletedCount = 0;
|
let deletedCount = 0;
|
||||||
let cursor: MiDriveFile['id'] | null = null;
|
let cursor: MiDriveFile['id'] | null = null;
|
||||||
|
|
||||||
|
const total = await this.driveFilesRepository.countBy({
|
||||||
|
userId: user.id,
|
||||||
|
});
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
const files = await this.driveFilesRepository.find({
|
const files = await this.driveFilesRepository.find({
|
||||||
where: {
|
where: {
|
||||||
|
@ -67,11 +71,7 @@ export class DeleteDriveFilesProcessorService {
|
||||||
deletedCount++;
|
deletedCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
const total = await this.driveFilesRepository.countBy({
|
job.updateProgress(deletedCount / total * 100);
|
||||||
userId: user.id,
|
|
||||||
});
|
|
||||||
|
|
||||||
job.updateProgress(deletedCount / total);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.logger.succ(`All drive files (${deletedCount}) of ${user.id} has been deleted.`);
|
this.logger.succ(`All drive files (${deletedCount}) of ${user.id} has been deleted.`);
|
||||||
|
|
|
@ -58,6 +58,10 @@ export class ExportBlockingProcessorService {
|
||||||
let exportedCount = 0;
|
let exportedCount = 0;
|
||||||
let cursor: MiBlocking['id'] | null = null;
|
let cursor: MiBlocking['id'] | null = null;
|
||||||
|
|
||||||
|
const total = await this.blockingsRepository.countBy({
|
||||||
|
blockerId: user.id,
|
||||||
|
});
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
const blockings = await this.blockingsRepository.find({
|
const blockings = await this.blockingsRepository.find({
|
||||||
where: {
|
where: {
|
||||||
|
@ -97,11 +101,7 @@ export class ExportBlockingProcessorService {
|
||||||
exportedCount++;
|
exportedCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
const total = await this.blockingsRepository.countBy({
|
job.updateProgress(exportedCount / total * 100);
|
||||||
blockerId: user.id,
|
|
||||||
});
|
|
||||||
|
|
||||||
job.updateProgress(exportedCount / total);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
stream.end();
|
stream.end();
|
||||||
|
|
|
@ -95,6 +95,10 @@ export class ExportClipsProcessorService {
|
||||||
let exportedClipsCount = 0;
|
let exportedClipsCount = 0;
|
||||||
let cursor: MiClip['id'] | null = null;
|
let cursor: MiClip['id'] | null = null;
|
||||||
|
|
||||||
|
const total = await this.clipsRepository.countBy({
|
||||||
|
userId: user.id,
|
||||||
|
});
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
const clips = await this.clipsRepository.find({
|
const clips = await this.clipsRepository.find({
|
||||||
where: {
|
where: {
|
||||||
|
@ -126,11 +130,7 @@ export class ExportClipsProcessorService {
|
||||||
exportedClipsCount++;
|
exportedClipsCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
const total = await this.clipsRepository.countBy({
|
job.updateProgress(exportedClipsCount / total * 100);
|
||||||
userId: user.id,
|
|
||||||
});
|
|
||||||
|
|
||||||
job.updateProgress(exportedClipsCount / total);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -78,6 +78,10 @@ export class ExportFavoritesProcessorService {
|
||||||
let exportedFavoritesCount = 0;
|
let exportedFavoritesCount = 0;
|
||||||
let cursor: MiNoteFavorite['id'] | null = null;
|
let cursor: MiNoteFavorite['id'] | null = null;
|
||||||
|
|
||||||
|
const total = await this.noteFavoritesRepository.countBy({
|
||||||
|
userId: user.id,
|
||||||
|
});
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
const favorites = await this.noteFavoritesRepository.find({
|
const favorites = await this.noteFavoritesRepository.find({
|
||||||
where: {
|
where: {
|
||||||
|
@ -109,11 +113,7 @@ export class ExportFavoritesProcessorService {
|
||||||
exportedFavoritesCount++;
|
exportedFavoritesCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
const total = await this.noteFavoritesRepository.countBy({
|
job.updateProgress(exportedFavoritesCount / total * 100);
|
||||||
userId: user.id,
|
|
||||||
});
|
|
||||||
|
|
||||||
job.updateProgress(exportedFavoritesCount / total);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
await write(']');
|
await write(']');
|
||||||
|
|
|
@ -58,6 +58,10 @@ export class ExportMutingProcessorService {
|
||||||
let exportedCount = 0;
|
let exportedCount = 0;
|
||||||
let cursor: MiMuting['id'] | null = null;
|
let cursor: MiMuting['id'] | null = null;
|
||||||
|
|
||||||
|
const total = await this.mutingsRepository.countBy({
|
||||||
|
muterId: user.id,
|
||||||
|
});
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
const mutes = await this.mutingsRepository.find({
|
const mutes = await this.mutingsRepository.find({
|
||||||
where: {
|
where: {
|
||||||
|
@ -98,11 +102,7 @@ export class ExportMutingProcessorService {
|
||||||
exportedCount++;
|
exportedCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
const total = await this.mutingsRepository.countBy({
|
job.updateProgress(exportedCount / total * 100);
|
||||||
muterId: user.id,
|
|
||||||
});
|
|
||||||
|
|
||||||
job.updateProgress(exportedCount / total);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
stream.end();
|
stream.end();
|
||||||
|
|
|
@ -37,6 +37,8 @@ class NoteStream extends ReadableStream<Record<string, unknown>> {
|
||||||
let exportedNotesCount = 0;
|
let exportedNotesCount = 0;
|
||||||
let cursor: MiNote['id'] | null = null;
|
let cursor: MiNote['id'] | null = null;
|
||||||
|
|
||||||
|
const totalPromise = notesRepository.countBy({ userId });
|
||||||
|
|
||||||
const serialize = (
|
const serialize = (
|
||||||
note: MiNote,
|
note: MiNote,
|
||||||
poll: MiPoll | null,
|
poll: MiPoll | null,
|
||||||
|
@ -88,8 +90,8 @@ class NoteStream extends ReadableStream<Record<string, unknown>> {
|
||||||
exportedNotesCount++;
|
exportedNotesCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
const total = await notesRepository.countBy({ userId });
|
const total = await totalPromise;
|
||||||
job.updateProgress(exportedNotesCount / total);
|
job.updateProgress(exportedNotesCount / total * 100);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ SPDX-License-Identifier: AGPL-3.0-only
|
||||||
</template>
|
</template>
|
||||||
<template #suffix>
|
<template #suffix>
|
||||||
<MkTime :time="job.finishedOn ?? job.processedOn ?? job.timestamp" mode="relative"/>
|
<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.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-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>
|
<span v-else-if="job.isFailed" style="margin-left: 1em; color: var(--MI_THEME-warn)"><i class="ti ti-alert-triangle"></i></span>
|
||||||
|
|
Loading…
Reference in New Issue