From cf8dede82dd05d963ba7de1192e4fb6451331d3e Mon Sep 17 00:00:00 2001 From: Sven Sauleau Date: Mon, 20 Feb 2023 17:03:37 +0000 Subject: [PATCH] List followers/following uses cache and handle failures --- functions/api/v1/accounts/[id]/followers.ts | 10 +++++++--- functions/api/v1/accounts/[id]/following.ts | 10 +++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/functions/api/v1/accounts/[id]/followers.ts b/functions/api/v1/accounts/[id]/followers.ts index 2887a4e..010e6cf 100644 --- a/functions/api/v1/accounts/[id]/followers.ts +++ b/functions/api/v1/accounts/[id]/followers.ts @@ -67,10 +67,14 @@ async function getLocalFollowers(request: Request, handle: Handle, db: D1Databas for (let i = 0, len = followers.length; i < len; i++) { const id = new URL(followers[i]) - const acct = urlToHandle(id) - const actor = await actors.get(id) - out.push(await loadExternalMastodonAccount(acct, actor)) + + try { + const actor = await actors.getAndCache(id, db) + out.push(await loadExternalMastodonAccount(acct, actor)) + } catch (err: any) { + console.warn(`failed to retrieve follower (${id}): ${err.message}`) + } } const headers = { diff --git a/functions/api/v1/accounts/[id]/following.ts b/functions/api/v1/accounts/[id]/following.ts index ae53f85..f149f8e 100644 --- a/functions/api/v1/accounts/[id]/following.ts +++ b/functions/api/v1/accounts/[id]/following.ts @@ -67,10 +67,14 @@ async function getLocalFollowing(request: Request, handle: Handle, db: D1Databas for (let i = 0, len = following.length; i < len; i++) { const id = new URL(following[i]) - const acct = urlToHandle(id) - const actor = await actors.get(id) - out.push(await loadExternalMastodonAccount(acct, actor)) + + try { + const actor = await actors.getAndCache(id, db) + out.push(await loadExternalMastodonAccount(acct, actor)) + } catch (err: any) { + console.warn(`failed to retrieve following (${id}): ${err.message}`) + } } const headers = {