diff --git a/src/app/teams/[teamId]/hooks/use-create-role.tsx b/src/app/teams/[teamId]/hooks/use-create-role.tsx index 770fed0..661a339 100644 --- a/src/app/teams/[teamId]/hooks/use-create-role.tsx +++ b/src/app/teams/[teamId]/hooks/use-create-role.tsx @@ -222,10 +222,6 @@ export function useCreateRole({ }); setNodes(updatedNodes); } - - // Invalidate caches for background refresh - void utils.team.getById.invalidate({ id: teamId }); - void utils.role.getByTeamId.invalidate({ teamId }); }, onError: (error, _variables, context) => { if (context?.previousRoles !== undefined) { diff --git a/src/app/teams/[teamId]/hooks/use-delete-role.tsx b/src/app/teams/[teamId]/hooks/use-delete-role.tsx index fd290d3..4d6be8d 100644 --- a/src/app/teams/[teamId]/hooks/use-delete-role.tsx +++ b/src/app/teams/[teamId]/hooks/use-delete-role.tsx @@ -79,10 +79,5 @@ export function useDeleteRole(teamId: string) { setEdges?.(context.previousEdges); } }, - onSettled: () => { - void utils.role.getByTeamId.invalidate({ teamId }); - // Invalidate team.getById cache to ensure fresh data on next fetch - void utils.team.getById.invalidate({ id: teamId }); - }, }); } diff --git a/src/components/role/role-card.tsx b/src/components/role/role-card.tsx index c24adc9..1dc7268 100644 --- a/src/components/role/role-card.tsx +++ b/src/components/role/role-card.tsx @@ -137,13 +137,6 @@ function RoleCardComponent({ utils.role.getByTeamId.setData({ teamId }, context.previousRoles); } }, - onSettled: () => { - if (teamId) { - void utils.role.getByTeamId.invalidate({ teamId }); - void utils.team.getById.invalidate({ id: teamId }); - void utils.dashboard.getDashboardCharts.invalidate({ teamId }); - } - }, }); const handleDelete = useCallback(async () => { diff --git a/src/hooks/use-optimistic-role-update.ts b/src/hooks/use-optimistic-role-update.ts index 229fac6..9f4de40 100644 --- a/src/hooks/use-optimistic-role-update.ts +++ b/src/hooks/use-optimistic-role-update.ts @@ -218,13 +218,6 @@ export function useOptimisticRoleUpdate(teamId: string) { return chart; }); }); - - // Delayed invalidation for eventual consistency - // Wait for Prisma Accelerate cache propagation before background refresh - setTimeout(() => { - void utils.role.getByTeamId.invalidate({ teamId }); - void utils.dashboard.getDashboardCharts.invalidate({ teamId }); - }, 5000); }, onError: (error, _vars, context) => { diff --git a/src/server/api/routers/metric.ts b/src/server/api/routers/metric.ts index 903aacb..a06e187 100644 --- a/src/server/api/routers/metric.ts +++ b/src/server/api/routers/metric.ts @@ -9,7 +9,10 @@ import { getMetricAndVerifyAccess, getTeamAndVerifyAccess, } from "@/server/api/utils/authorization"; -import { invalidateDashboardCache } from "@/server/api/utils/cache-strategy"; +import { + invalidateCacheByTags, + invalidateDashboardCache, +} from "@/server/api/utils/cache-strategy"; import { runBackgroundTask } from "./pipeline"; @@ -267,12 +270,13 @@ export const metricRouter = createTRPCRouter({ where: { id: input.id }, }); - // Invalidate Prisma cache for dashboard queries + // Invalidate Prisma cache for dashboard and role queries await invalidateDashboardCache( ctx.db, metric.organizationId, metric.teamId, ); + await invalidateCacheByTags(ctx.db, [`team_${metric.teamId}`]); return { success: true }; }),