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]); }); } }