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.

fix propagateBulkLinkChanges

Kiran K86dfec9200eb
diff --git a/apps/web/lib/api/links/cache.ts b/apps/web/lib/api/links/cache.ts
index 3cdcfcdc89..18aacc88d0 100644
--- a/apps/web/lib/api/links/cache.ts
+++ b/apps/web/lib/api/links/cache.ts
@@ -20,9 +20,13 @@ class LinkCache {
);
redisLinks.map(({ domain, key, ...redisLink }) =>
- pipeline.set(`${domain}:${key}`, JSON.stringify(redisLink), {
- ex: CACHE_EXPIRATION,
- }),
+ pipeline.set(
+ this._createKey({ domain, key }),
+ JSON.stringify(redisLink),
+ {
+ ex: CACHE_EXPIRATION,
+ },
+ ),
);
return await pipeline.exec();
diff --git a/apps/web/lib/api/links/propagate-bulk-link-changes.ts b/apps/web/lib/api/links/propagate-bulk-link-changes.ts
index 4721df8d56..76bfb16867 100644
--- a/apps/web/lib/api/links/propagate-bulk-link-changes.ts
+++ b/apps/web/lib/api/links/propagate-bulk-link-changes.ts
@@ -1,34 +1,12 @@
import { recordLink } from "@/lib/tinybird";
-import { RedisLinkProps } from "@/lib/types";
-import { formatRedisLink, redis } from "@/lib/upstash";
+import { linkCache } from "./cache";
import { LinkWithTags } from "./utils";
export async function propagateBulkLinkChanges(links: LinkWithTags[]) {
- const pipeline = redis.pipeline();
-
- // split links into domains for better write effeciency in Redis
- const linksByDomain: Record<string, Record<string, RedisLinkProps>> = {};
-
- await Promise.all(
- links.map(async (link) => {
- const { domain, key } = link;
-
- if (!linksByDomain[domain]) {
- linksByDomain[domain] = {};
- }
- // this technically will be a synchronous function since isIframeable won't be run for bulk link creation
- const formattedLink = await formatRedisLink(link);
- linksByDomain[domain][key.toLowerCase()] = formattedLink;
- }),
- );
-
- Object.entries(linksByDomain).forEach(([domain, links]) => {
- pipeline.hset(domain.toLowerCase(), links);
- });
-
await Promise.all([
// update Redis
- pipeline.exec(),
+ linkCache.mset(links),
+
// update Tinybird
recordLink(
links.map((link) => ({