From e446a11bb7ed10875eceb50cbd4261523ae4de4f Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Sat, 3 Dec 2022 02:13:18 -0500 Subject: [PATCH] Revert "server: fetch meta only once in skippedInstances" This reverts commit 81d63720f2671f83e24432c8052b1f2efea6c1c7 since it seems to cause a ReferenceError for some reason. Ref: https://toot.site/@jeder/109447151582516733 --- packages/backend/src/misc/skipped-instances.ts | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/packages/backend/src/misc/skipped-instances.ts b/packages/backend/src/misc/skipped-instances.ts index 40f106746..97e654b25 100644 --- a/packages/backend/src/misc/skipped-instances.ts +++ b/packages/backend/src/misc/skipped-instances.ts @@ -2,7 +2,6 @@ import { db } from '@/db/postgre.js'; import { fetchMeta } from '@/misc/fetch-meta.js'; import { Instance } from '@/models/entities/instance.js'; import { DAY } from '@/const.js'; -import { Meta } from '@/models/entities/meta.js'; // Threshold from last contact after which an instance will be considered // "dead" and should no longer get activities delivered to it. @@ -27,11 +26,10 @@ function matchHost(host: Instance['host'], pattern: string): boolean { * 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 (oprional) * @returns whether the given host should be blocked */ -export async function shouldBlockInstance(host: string, meta: Promise = fetchMeta()): Promise { - const { blockedHosts } = await meta; +export async function shouldBlockInstance(host: string): Promise { + const { blockedHosts } = await fetchMeta(); return blockedHosts.some(blockedHost => matchHost(host, blockedHost)); } @@ -43,8 +41,7 @@ export async function shouldBlockInstance(host: string, meta: Promise = fe */ export async function skippedInstances(hosts: Array): Promise> { // Resolve the boolean promises before filtering - const meta = fetchMeta(); - const shouldSkip = await Promise.all(hosts.map(host => shouldBlockInstance(host, meta))); + const shouldSkip = await Promise.all(hosts.map(shouldBlockInstance)); const skipped = hosts.filter((_, i) => shouldSkip[i]); // if possible return early and skip accessing the database