From 4183c429e61f140192b9ffcfe595cf003ecf91f8 Mon Sep 17 00:00:00 2001 From: Johann150 Date: Fri, 18 Nov 2022 22:02:07 +0100 Subject: [PATCH] server: rewrite skipped instances query in raw SQL This should hopefully improve performance somewhat. Reviewed-on: https://akkoma.dev/FoundKeyGang/FoundKey/pulls/230 Changelog: Changed --- .../backend/src/misc/skipped-instances.ts | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/packages/backend/src/misc/skipped-instances.ts b/packages/backend/src/misc/skipped-instances.ts index 3d3d333b8..3f13a8f7a 100644 --- a/packages/backend/src/misc/skipped-instances.ts +++ b/packages/backend/src/misc/skipped-instances.ts @@ -1,4 +1,5 @@ import { Brackets } from 'typeorm'; +import { db } from '@/db/postgre.js'; import { fetchMeta } from '@/misc/fetch-meta.js'; import { Instances } from '@/models/index.js'; import { Instance } from '@/models/entities/instance.js'; @@ -25,19 +26,16 @@ export async function skippedInstances(hosts: Array): Array !skipped.includes(host)), - }) - .andWhere(new Brackets(qb => { qb - .where('instance.isSuspended') - .orWhere('instance.lastCommunicatedAt < :deadTime', { deadTime }) - .orWhere('instance.latestStatus = 410'); - })) - .select('host') - .getRawMany() + hosts.filter(host => !skipped.includes(host) && !host.includes(',')).join(','), + ], + ) + .then(res => res.map(row => row.host)) ); }