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.

Merge branch 'main' into redis

Steven Tey9a6849014370
diff --cc apps/web/lib/api/links/propagate-bulk-link-changes.ts
index 76bfb16867,c5f9479bc4..7f87fd2338
--- a/apps/web/lib/api/links/propagate-bulk-link-changes.ts
+++ b/apps/web/lib/api/links/propagate-bulk-link-changes.ts
@@@ -1,12 -1,34 +1,36 @@@
import { recordLink } from "@/lib/tinybird";
+ import { RedisLinkProps } from "@/lib/types";
+ import { formatRedisLink, redis } from "@/lib/upstash";
+import { linkCache } from "./cache";
- import { LinkWithTags } from "./utils";
+ import { ExpandedLink } from "./utils";
+
+ export async function propagateBulkLinkChanges(links: ExpandedLink[]) {
+ 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);
+ });
- export async function propagateBulkLinkChanges(links: LinkWithTags[]) {
await Promise.all([
// update Redis
- pipeline.exec(),
+ linkCache.mset(links),
+
// update Tinybird
recordLink(
links.map((link) => ({