From 18cf228f893806e690be37729c75d66b32080784 Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Sat, 3 Dec 2022 05:12:08 -0500 Subject: [PATCH] server: readd "fetch meta only once in skippedInstances"" This reverts commit e446a11bb7ed10875eceb50cbd4261523ae4de4f. Turns out this wasn't really the source of the referenced issue and someone was able to run with the original commit fine, so adding this back for now. --- packages/backend/src/misc/skipped-instances.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/backend/src/misc/skipped-instances.ts b/packages/backend/src/misc/skipped-instances.ts index 97e654b25..40f106746 100644 --- a/packages/backend/src/misc/skipped-instances.ts +++ b/packages/backend/src/misc/skipped-instances.ts @@ -2,6 +2,7 @@ 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. @@ -26,10 +27,11 @@ 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): Promise { - const { blockedHosts } = await fetchMeta(); +export async function shouldBlockInstance(host: string, meta: Promise = fetchMeta()): Promise { + const { blockedHosts } = await meta; return blockedHosts.some(blockedHost => matchHost(host, blockedHost)); } @@ -41,7 +43,8 @@ export async function shouldBlockInstance(host: string): Promise { */ export async function skippedInstances(hosts: Array): Promise> { // Resolve the boolean promises before filtering - const shouldSkip = await Promise.all(hosts.map(shouldBlockInstance)); + const meta = fetchMeta(); + const shouldSkip = await Promise.all(hosts.map(host => shouldBlockInstance(host, meta))); const skipped = hosts.filter((_, i) => shouldSkip[i]); // if possible return early and skip accessing the database