Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Add fallback support for Redis timeouts

Steven Tey145662e13f25
diff --git a/apps/web/lib/middleware/link.ts b/apps/web/lib/middleware/link.ts
index d48ca2b020..9f4703c4a2 100644
--- a/apps/web/lib/middleware/link.ts
+++ b/apps/web/lib/middleware/link.ts
@@ -32,6 +32,7 @@ import { recordClickCache } from "../api/links/record-click-cache";
import { getLinkViaEdge } from "../planetscale";
import { getDomainViaEdge } from "../planetscale/get-domain-via-edge";
import { getPartnerAndDiscount } from "../planetscale/get-partner-discount";
+import { RedisLinkProps } from "../types";
import { cacheDeepLinkClickData } from "./utils/cache-deeplink-click-data";
import { crawlBitly } from "./utils/crawl-bitly";
import { isIosAppStoreUrl } from "./utils/is-ios-app-store-url";
@@ -79,7 +80,21 @@ export default async function LinkMiddleware(
});
}
- let cachedLink = await linkCache.get({ domain, key });
+ let cachedLink: RedisLinkProps | null = null;
+ try {
+ const controller = new AbortController();
+ const timeoutId = setTimeout(() => controller.abort(), 1000);
+
+ cachedLink = await linkCache.get({ domain, key });
+ clearTimeout(timeoutId);
+ } catch (error) {
+ console.error(
+ "[LinkMiddleware] – Timeout getting cached link from Redis:",
+ error,
+ );
+ cachedLink = null;
+ }
+
let isPartnerLink = Boolean(cachedLink?.programId && cachedLink?.partnerId);
if (!cachedLink) {