From 6583d0c43d9af262f4a33679f0490bdfb4863420 Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Sat, 24 Dec 2022 14:56:39 -0500 Subject: [PATCH] server: pass in resolved meta table to shouldBlockInstance This should make it more friendly to use in places where the meta table has already been resolved for other reasons. --- packages/backend/src/misc/should-block-instance.ts | 7 +++---- packages/backend/src/misc/skipped-instances.ts | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/packages/backend/src/misc/should-block-instance.ts b/packages/backend/src/misc/should-block-instance.ts index 7396983d7..ddd25eeee 100644 --- a/packages/backend/src/misc/should-block-instance.ts +++ b/packages/backend/src/misc/should-block-instance.ts @@ -6,11 +6,10 @@ import { Meta } from '@/models/entities/meta.js'; * Returns whether a specific host (punycoded) should be blocked. * * @param host punycoded instance host - * @param meta a Promise contatining the information from the meta table (optional) + * @param meta a resolved Meta table * @returns whether the given host should be blocked */ - -export async function shouldBlockInstance(host: Instance['host'], meta: Promise = fetchMeta()): Promise { - const { blockedHosts } = await meta; +export async function shouldBlockInstance(host: Instance['host'], meta?: Meta): Promise { + const { blockedHosts } = meta ?? await fetchMeta(); return blockedHosts.some(blockedHost => host === blockedHost || host.endsWith('.' + blockedHost)); } diff --git a/packages/backend/src/misc/skipped-instances.ts b/packages/backend/src/misc/skipped-instances.ts index f5b5c3b73..1772ac878 100644 --- a/packages/backend/src/misc/skipped-instances.ts +++ b/packages/backend/src/misc/skipped-instances.ts @@ -16,7 +16,7 @@ const deadThreshold = 7 * DAY; */ export async function skippedInstances(hosts: Array): Promise> { // Resolve the boolean promises before filtering - const meta = fetchMeta(); + const meta = await fetchMeta(); const shouldSkip = await Promise.all(hosts.map(host => shouldBlockInstance(host, meta))); const skipped = hosts.filter((_, i) => shouldSkip[i]);