From 3799fe3167804b66af4c03edd78851242c1851fc Mon Sep 17 00:00:00 2001 From: riku6460 <17585784+riku6460@users.noreply.github.com> Date: Fri, 18 Oct 2024 22:26:56 +0900 Subject: [PATCH] =?UTF-8?q?queue=20=E3=81=AE=20delayed=20=E3=81=AE?= =?UTF-8?q?=E4=BB=B6=E6=95=B0=E3=81=8C=E5=A2=97=E3=81=88=E3=81=9F=E9=9A=9B?= =?UTF-8?q?=E3=81=AB=20deliver-delayed=20=E3=81=A8=20inbox-delayed=20?= =?UTF-8?q?=E3=81=8C=E8=BF=94=E3=81=A3=E3=81=A6=E3=81=93=E3=81=AA=E3=81=8F?= =?UTF-8?q?=E3=81=AA=E3=82=8B=E5=95=8F=E9=A1=8C=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/endpoints/admin/queue/deliver-delayed.ts | 12 +++++------- .../api/endpoints/admin/queue/inbox-delayed.ts | 12 +++++------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/packages/backend/src/server/api/endpoints/admin/queue/deliver-delayed.ts b/packages/backend/src/server/api/endpoints/admin/queue/deliver-delayed.ts index acc1554289b1..6e738498e7ef 100644 --- a/packages/backend/src/server/api/endpoints/admin/queue/deliver-delayed.ts +++ b/packages/backend/src/server/api/endpoints/admin/queue/deliver-delayed.ts @@ -56,7 +56,7 @@ export default class extends Endpoint { // eslint- super(meta, paramDef, async (ps, me) => { const jobs = await this.deliverQueue.getJobs(['delayed']); - const res = [] as [string, number][]; + const res = new Map(); for (const job of jobs) { let host: string; @@ -68,17 +68,15 @@ export default class extends Endpoint { // eslint- continue; } - const found = res.find(x => x[0] === host); + const found = res.get(host); if (found) { - found[1]++; + res.set(host, found + 1); } else { - res.push([host, 1]); + res.set(host, 1); } } - res.sort((a, b) => b[1] - a[1]); - - return res; + return Array.from(res.entries()).sort((a, b) => b[1] - a[1]); }); } } diff --git a/packages/backend/src/server/api/endpoints/admin/queue/inbox-delayed.ts b/packages/backend/src/server/api/endpoints/admin/queue/inbox-delayed.ts index add65fe3354b..cdfa9051dbb7 100644 --- a/packages/backend/src/server/api/endpoints/admin/queue/inbox-delayed.ts +++ b/packages/backend/src/server/api/endpoints/admin/queue/inbox-delayed.ts @@ -56,7 +56,7 @@ export default class extends Endpoint { // eslint- super(meta, paramDef, async (ps, me) => { const jobs = await this.inboxQueue.getJobs(['delayed']); - const res = [] as [string, number][]; + const res = new Map(); for (const job of jobs) { let host: string; @@ -68,17 +68,15 @@ export default class extends Endpoint { // eslint- continue; } - const found = res.find(x => x[0] === host); + const found = res.get(host); if (found) { - found[1]++; + res.set(host, found + 1); } else { - res.push([host, 1]); + res.set(host, 1); } } - res.sort((a, b) => b[1] - a[1]); - - return res; + return Array.from(res.entries()).sort((a, b) => b[1] - a[1]); }); } }