The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
address CR feedback
Steven Tey9327f1f533c4
diff --git a/apps/web/app/api/workspaces/[idOrSlug]/route.ts b/apps/web/app/api/workspaces/[idOrSlug]/route.tsindex 2ba5d8f7b1..14b6d8f0d0 100644--- a/apps/web/app/api/workspaces/[idOrSlug]/route.ts+++ b/apps/web/app/api/workspaces/[idOrSlug]/route.ts@@ -3,8 +3,8 @@ import { DubApiError } from "@/lib/api/errors";import { parseRequestBody } from "@/lib/api/utils";import { validateAllowedHostnames } from "@/lib/api/validate-allowed-hostnames";import { deleteWorkspace } from "@/lib/api/workspaces/delete-workspace";-import { workspaceProductCache } from "@/lib/api/workspaces/workspace-product-cache";import { prefixWorkspaceId } from "@/lib/api/workspaces/workspace-id";+import { workspaceProductCache } from "@/lib/api/workspaces/workspace-product-cache";import { withWorkspace } from "@/lib/auth";import { getFeatureFlags } from "@/lib/edge-config";import { jackson } from "@/lib/jackson";@@ -219,27 +219,34 @@ export const PATCH = withWorkspace(},});- if (updatedWorkspace.slug !== workspace.slug) {- await Promise.allSettled([- prisma.user.updateMany({- where: {- defaultWorkspace: workspace.slug,- },- data: {- defaultWorkspace: updatedWorkspace.slug,- },- }),- // refresh the workspace product cache for both workspaces- workspaceProductCache.delete({ slug: workspace.slug }),- workspaceProductCache.set({- slug: updatedWorkspace.slug,- product: updatedWorkspace.defaultProduct,- }),- ]);- } else if (updatedWorkspace.defaultProduct !== workspace.defaultProduct) {- // refresh the workspace product cache for the workspace (if updated)- await workspaceProductCache.delete({ slug: updatedWorkspace.slug });- }+ await Promise.allSettled([+ ...(updatedWorkspace.slug !== workspace.slug+ ? [+ prisma.user.updateMany({+ where: {+ defaultWorkspace: workspace.slug,+ },+ data: {+ defaultWorkspace: updatedWorkspace.slug,+ },+ }),+ // update the workspace product cache for both workspaces+ workspaceProductCache.set({+ slug: updatedWorkspace.slug,+ product: updatedWorkspace.defaultProduct,+ }),+ workspaceProductCache.delete({ slug: workspace.slug }),+ ]+ : // if only the product has changed, update the cache+ updatedWorkspace.defaultProduct !== workspace.defaultProduct+ ? [+ workspaceProductCache.set({+ slug: updatedWorkspace.slug,+ product: updatedWorkspace.defaultProduct,+ }),+ ]+ : []),+ ]);waitUntil((async () => {diff --git a/apps/web/lib/middleware/utils/get-workspace-product.ts b/apps/web/lib/middleware/utils/get-workspace-product.tsindex af76420952..dc78fce95a 100644--- a/apps/web/lib/middleware/utils/get-workspace-product.ts+++ b/apps/web/lib/middleware/utils/get-workspace-product.ts@@ -5,7 +5,9 @@ import { after } from "next/server";export const getWorkspaceProduct = async (workspaceSlug: string) => {try {- let workspaceProduct = await workspaceProductCache.get({ slug: workspaceSlug });+ let workspaceProduct = await workspaceProductCache.get({+ slug: workspaceSlug,+ });if (workspaceProduct) {return workspaceProduct;}@@ -20,7 +22,9 @@ export const getWorkspaceProduct = async (workspaceSlug: string) => {? (rows[0] as WorkspaceProps): null;- workspaceProduct = workspace?.defaultProduct ?? "links";+ workspaceProduct =+ workspace?.defaultProduct ??+ (workspace?.defaultProgramId ? "program" : "links");after(async () => {await workspaceProductCache.set({