From bdf2e14a73a067b5165aad2e0bfced8ff235a156 Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Sat, 3 Dec 2022 04:01:51 -0500 Subject: [PATCH] server: fix TypeError in registerOrFetchInstanceDoc Changelog: Fixed --- .../src/services/register-or-fetch-instance-doc.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/backend/src/services/register-or-fetch-instance-doc.ts b/packages/backend/src/services/register-or-fetch-instance-doc.ts index 8c625ff21..3d41fafa1 100644 --- a/packages/backend/src/services/register-or-fetch-instance-doc.ts +++ b/packages/backend/src/services/register-or-fetch-instance-doc.ts @@ -7,14 +7,18 @@ import { HOUR } from '@/const.js'; const cache = new Cache( HOUR, - (host) => Instances.findOneBy({ host }).then(x => x ?? undefined), + async (host) => { + if (host == null) return undefined; + const res = await Instances.findOneBy({ host }); + return res ?? undefined; + } , ); export async function registerOrFetchInstanceDoc(idnHost: string): Promise { const host = toPuny(idnHost); - const cached = cache.fetch(host); - if (cached) return cached; + const cached = await cache.fetch(host); + if (cached != null) return cached; // apparently a new instance const i = await Instances.insert({