Dough Git

commit

Add timeouts to third-party fetches, disable clientBadges for now

commit
9d6747b20882d5f94bf1efaf68ac59a757769888
author
Clove Twilight <[email protected]>
date
2026-08-11 18:55
Timing found the actual culprit: getClientBadges (badges.equicord.org)
was hanging ~11.5s with no timeout, blocking the whole profile response
past the bot's 10s limit. That service is currently down, so the call
is disabled at the site for now rather than eating a timeout on every
request. Added a 5s AbortSignal timeout to it and the other three
third-party lookups (pronoundb, timezone, reviewdb) so none of them can
do this again.

Co-Authored-By: Claude Sonnet 5 <[email protected]>

diff --git a/src/discord/clientBadges.ts b/src/discord/clientBadges.ts
index 70577a9..f375d3e 100644
--- a/src/discord/clientBadges.ts
+++ b/src/discord/clientBadges.ts
@@ -77,7 +77,7 @@ export async function getClientBadges(
 async function fetchClientBadges(id: string): Promise<UnifiedClientBadge[] | undefined> {
   let res: Response;
   try {
-    res = await fetch(`${API_BASE}/${id}`);
+    res = await fetch(`${API_BASE}/${id}`, { signal: AbortSignal.timeout(5000) });
   } catch {
     return undefined;
   }
diff --git a/src/profile.ts b/src/profile.ts
index c6d3d1b..e24790d 100644
--- a/src/profile.ts
+++ b/src/profile.ts
@@ -20,7 +20,7 @@ import type {
   UnifiedUser,
   UnifiedWishlistItem,
 } from "./types";
-import { getClientBadges } from "./discord/clientBadges";
+// import { getClientBadges } from "./discord/clientBadges"; // badges.equicord.org is down — disabled below
 import {
   avatarDecorationImageUrl,
   avatarUrl,
@@ -616,11 +616,9 @@ async function buildFreshProfile(
   force = false
 ): Promise<BuildResult> {
   // Rich path first (unless we're cooling down from a 429); fall back to bot.
-  const _t0 = Date.now();
   const rich = tryRich
     ? await fetchUserProfile(env, id)
     : { data: null, status: 0, retryAfter: 0 };
-  console.log(`[timing] fetchUserProfile: ${Date.now() - _t0}ms (status=${rich.status})`);
   const richStatus = rich.status;
   const retryAfter = rich.retryAfter;
   const profile = rich.data;
@@ -668,19 +666,15 @@ async function buildFreshProfile(
 
     // Fetch everything that doesn't depend on the profile body in parallel.
     // Wishlist + equipped collectibles need the profile, so they run alongside.
-    const _timed = <T,>(label: string, p: Promise<T>): Promise<T> => {
-      const start = Date.now();
-      return p.finally(() => console.log(`[timing] ${label}: ${Date.now() - start}ms`));
-    };
     const [wishlist, collectibles, clientBadges, memberships, pronoundb, timezone, reviews] =
       await Promise.all([
-        _timed("buildWishlist", buildWishlist(env, profile, ctx, force)),
-        _timed("buildCollectibles", buildCollectibles(env, profile, ctx, force)),
-        _timed("getClientBadges", getClientBadges(env, id, ctx, force)),
-        _timed("getMemberships", getMemberships(env, id, ctx, force).catch(() => null)),
-        _timed("getPronouns", getPronouns(env, id, ctx, force).catch(() => null)),
-        _timed("getTimezone", getTimezone(env, id, ctx, force).catch(() => null)),
-        _timed("getReviews", getReviews(env, id, ctx, force).catch(() => null)),
+        buildWishlist(env, profile, ctx, force),
+        buildCollectibles(env, profile, ctx, force),
+        Promise.resolve(null), // clientBadges disabled — badges.equicord.org is down
+        getMemberships(env, id, ctx, force).catch(() => null),
+        getPronouns(env, id, ctx, force).catch(() => null),
+        getTimezone(env, id, ctx, force).catch(() => null),
+        getReviews(env, id, ctx, force).catch(() => null),
       ]);
 
     return {
@@ -713,7 +707,7 @@ async function buildFreshProfile(
   if (!u) return { result: null, richStatus, retryAfter };
   const [collectibles, clientBadges, memberships, pronoundb, timezone, reviews] = await Promise.all([
     buildCollectibles(env, { user: u }, ctx, force).catch(() => null),
-    getClientBadges(env, id, ctx, force),
+    Promise.resolve(null), // clientBadges disabled — badges.equicord.org is down
     getMemberships(env, id, ctx, force).catch(() => null),
     getPronouns(env, id, ctx, force).catch(() => null),
     getTimezone(env, id, ctx, force).catch(() => null),
diff --git a/src/thirdparty/pronoundb.ts b/src/thirdparty/pronoundb.ts
index 9ae81ea..dec1a8c 100644
--- a/src/thirdparty/pronoundb.ts
+++ b/src/thirdparty/pronoundb.ts
@@ -61,6 +61,7 @@ export async function getPronouns(
   try {
     const res = await fetch(`${apiBase(env)}/api/v2/lookup?platform=discord&ids=${id}`, {
       headers: { Accept: "application/json" },
+      signal: AbortSignal.timeout(5000),
     });
     if (res.status === 404) value = null;
     else if (!res.ok) value = undefined;
diff --git a/src/thirdparty/reviewdb.ts b/src/thirdparty/reviewdb.ts
index 6f978c9..b8bc805 100644
--- a/src/thirdparty/reviewdb.ts
+++ b/src/thirdparty/reviewdb.ts
@@ -84,6 +84,7 @@ export async function getReviews(
   try {
     const res = await fetch(`${apiBase(env)}/users/${id}/reviews`, {
       headers: { Accept: "application/json" },
+      signal: AbortSignal.timeout(5000),
     });
     if (res.status === 404) result = { count: 0, reviews: [] };
     else if (!res.ok) result = undefined;
diff --git a/src/thirdparty/timezone.ts b/src/thirdparty/timezone.ts
index 0d1aa41..7ca6dca 100644
--- a/src/thirdparty/timezone.ts
+++ b/src/thirdparty/timezone.ts
@@ -106,6 +106,7 @@ export async function getTimezone(
     try {
       const res = await fetch(`${apiBase(env)}/get?id=${id}`, {
         headers: { Accept: "application/json" },
+        signal: AbortSignal.timeout(5000),
       });
       if (res.status === 404) zone = null;
       else if (!res.ok) zone = undefined;