-
Notifications
You must be signed in to change notification settings - Fork 1
refactor: add cache invalidation consistency to role mutations #255
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughWalkthroughThe PR extends cache invalidation in role mutation hooks to include role-by-team cache alongside team cache. The server-side role router is updated to apply tag-based caching strategies to the getByTeamId route, ensuring consistent cache coherency for team-specific role data. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/server/api/routers/role.ts (1)
52-52: Prisma Accelerate caching appropriately applied togetByTeamId.The cache strategy with team-specific tags (
team_${input.teamId}) and 60s TTL/120s SWR is well-suited for role list queries. This integrates seamlessly with the tag-based invalidation already present in the mutation endpoints (lines 104, 173, 191).Consider applying a similar cache strategy to the
getByUserquery (lines 196-210) if user-specific role queries are frequently accessed. However, this can be deferred based on actual usage patterns and performance metrics.
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
src/app/teams/[teamId]/hooks/use-create-role.tsxsrc/app/teams/[teamId]/hooks/use-update-role.tsxsrc/server/api/routers/role.ts
🧰 Additional context used
📓 Path-based instructions (5)
**/*.{ts,tsx}
📄 CodeRabbit inference engine (CLAUDE.md)
**/*.{ts,tsx}: Use the tRPC dual API pattern: for server components, directly call tRPC server API (10x faster); for client components, use React hooks with TanStack Query
Use inline type imports with @trivago/prettier-plugin-sort-imports for consistent import orderingUse TypeScript 5.9 with strict type checking for all frontend and backend code
Files:
src/server/api/routers/role.tssrc/app/teams/[teamId]/hooks/use-update-role.tsxsrc/app/teams/[teamId]/hooks/use-create-role.tsx
src/server/api/routers/**/*.ts
📄 CodeRabbit inference engine (CLAUDE.md)
src/server/api/routers/**/*.ts: Always verify resource access using authorization helpers (getMetricAndVerifyAccess, getRoleAndVerifyAccess, getTeamAndVerifyAccess) to ensure resources belong to the user's organization in tRPC procedures
Use protectedProcedure or workspaceProcedure for new tRPC procedures instead of public procedures
Invalidate cache tags after mutations using invalidateCacheByTags(ctx.db, [tagName]) to maintain consistency
src/server/api/routers/**/*.ts: In tRPC procedures, never assume authentication; always use helpers likegetTeamAndVerifyAccessto verify access before operations
Be careful when modifying team save logic related toEditSessionmodel, which handles locking for concurrent team editing
Files:
src/server/api/routers/role.ts
src/**/*.tsx
📄 CodeRabbit inference engine (GEMINI.md)
Prefer Server Components for initial data fetching; use Client Components ('use client') only for interactivity
Files:
src/app/teams/[teamId]/hooks/use-update-role.tsxsrc/app/teams/[teamId]/hooks/use-create-role.tsx
src/**/*/*.tsx
📄 CodeRabbit inference engine (GEMINI.md)
Client Components must use
import { api } from '@/trpc/react'for standard HTTP/Hooks wrapper
Files:
src/app/teams/[teamId]/hooks/use-update-role.tsxsrc/app/teams/[teamId]/hooks/use-create-role.tsx
**/*.tsx
📄 CodeRabbit inference engine (GEMINI.md)
Use Tailwind CSS 4 for styling with shadcn/ui and Radix UI primitive components
Files:
src/app/teams/[teamId]/hooks/use-update-role.tsxsrc/app/teams/[teamId]/hooks/use-create-role.tsx
🧠 Learnings (13)
📓 Common learnings
Learnt from: CR
Repo: drifter089/orgOS PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-20T16:32:46.818Z
Learning: Applies to src/app/teams/[teamId]/**/*.{ts,tsx} : Cache-first node pattern: Role nodes store only roleId; fetch display data from TanStack Query cache using useRoleData hook rather than storing denormalized data
Learnt from: CR
Repo: drifter089/orgOS PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-20T16:32:46.818Z
Learning: Applies to src/server/api/routers/**/*.ts : Invalidate cache tags after mutations using invalidateCacheByTags(ctx.db, [tagName]) to maintain consistency
Learnt from: CR
Repo: drifter089/orgOS PR: 0
File: GEMINI.md:0-0
Timestamp: 2025-12-20T22:12:00.566Z
Learning: Applies to src/app/teams/[teamId]/**/*.tsx : React Flow nodes must store minimal data (e.g., just `roleId`); fetch full Role data from TanStack Query cache in the Node component to keep canvas and sidebars in sync
Learnt from: CR
Repo: drifter089/orgOS PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-20T16:32:46.818Z
Learning: Applies to src/app/teams/[teamId]/**/*.tsx : Consolidate role node duplication: extract shared RoleNodeTemplate from role-node.tsx and public-role-node.tsx with isEditable prop instead of maintaining separate components
📚 Learning: 2025-12-20T16:32:46.818Z
Learnt from: CR
Repo: drifter089/orgOS PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-20T16:32:46.818Z
Learning: Applies to src/app/teams/[teamId]/**/*.{ts,tsx} : Cache-first node pattern: Role nodes store only roleId; fetch display data from TanStack Query cache using useRoleData hook rather than storing denormalized data
Applied to files:
src/server/api/routers/role.tssrc/app/teams/[teamId]/hooks/use-update-role.tsxsrc/app/teams/[teamId]/hooks/use-create-role.tsx
📚 Learning: 2025-12-20T16:32:46.818Z
Learnt from: CR
Repo: drifter089/orgOS PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-20T16:32:46.818Z
Learning: Applies to src/server/api/routers/**/*.ts : Invalidate cache tags after mutations using invalidateCacheByTags(ctx.db, [tagName]) to maintain consistency
Applied to files:
src/server/api/routers/role.tssrc/app/teams/[teamId]/hooks/use-update-role.tsxsrc/app/teams/[teamId]/hooks/use-create-role.tsx
📚 Learning: 2025-12-20T16:32:46.818Z
Learnt from: CR
Repo: drifter089/orgOS PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-20T16:32:46.818Z
Learning: Applies to src/app/teams/[teamId]/**/*.tsx : Consolidate role node duplication: extract shared RoleNodeTemplate from role-node.tsx and public-role-node.tsx with isEditable prop instead of maintaining separate components
Applied to files:
src/server/api/routers/role.tssrc/app/teams/[teamId]/hooks/use-update-role.tsxsrc/app/teams/[teamId]/hooks/use-create-role.tsx
📚 Learning: 2025-12-20T22:12:00.566Z
Learnt from: CR
Repo: drifter089/orgOS PR: 0
File: GEMINI.md:0-0
Timestamp: 2025-12-20T22:12:00.566Z
Learning: Applies to src/app/teams/[teamId]/**/*.tsx : React Flow nodes must store minimal data (e.g., just `roleId`); fetch full Role data from TanStack Query cache in the Node component to keep canvas and sidebars in sync
Applied to files:
src/server/api/routers/role.tssrc/app/teams/[teamId]/hooks/use-update-role.tsxsrc/app/teams/[teamId]/hooks/use-create-role.tsx
📚 Learning: 2025-12-20T22:12:00.566Z
Learnt from: CR
Repo: drifter089/orgOS PR: 0
File: GEMINI.md:0-0
Timestamp: 2025-12-20T22:12:00.566Z
Learning: Applies to src/server/api/routers/**/*.ts : Be careful when modifying team save logic related to `EditSession` model, which handles locking for concurrent team editing
Applied to files:
src/server/api/routers/role.tssrc/app/teams/[teamId]/hooks/use-update-role.tsx
📚 Learning: 2025-12-20T16:32:46.818Z
Learnt from: CR
Repo: drifter089/orgOS PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-20T16:32:46.818Z
Learning: Applies to src/server/api/routers/**/*.ts : Always verify resource access using authorization helpers (getMetricAndVerifyAccess, getRoleAndVerifyAccess, getTeamAndVerifyAccess) to ensure resources belong to the user's organization in tRPC procedures
Applied to files:
src/server/api/routers/role.ts
📚 Learning: 2025-12-20T22:12:00.566Z
Learnt from: CR
Repo: drifter089/orgOS PR: 0
File: GEMINI.md:0-0
Timestamp: 2025-12-20T22:12:00.566Z
Learning: Applies to src/server/api/routers/**/*.ts : In tRPC procedures, never assume authentication; always use helpers like `getTeamAndVerifyAccess` to verify access before operations
Applied to files:
src/server/api/routers/role.ts
📚 Learning: 2025-12-20T22:12:00.566Z
Learnt from: CR
Repo: drifter089/orgOS PR: 0
File: GEMINI.md:0-0
Timestamp: 2025-12-20T22:12:00.566Z
Learning: Applies to src/app/teams/[teamId]/**/*.tsx : Avoid modifying `enrichNodesWithRoleData` flow without understanding the complete canvas serialization logic for saving/loading React Flow nodes to the database
Applied to files:
src/app/teams/[teamId]/hooks/use-update-role.tsxsrc/app/teams/[teamId]/hooks/use-create-role.tsx
📚 Learning: 2025-12-20T16:32:46.818Z
Learnt from: CR
Repo: drifter089/orgOS PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-20T16:32:46.818Z
Learning: Applies to src/app/teams/[teamId]/**/*.{ts,tsx} : Use Zustand store with Context pattern (TeamStoreContext) and access via useTeamStore hook. For callbacks that need current state, use useTeamStoreApi() to avoid stale closures.
Applied to files:
src/app/teams/[teamId]/hooks/use-update-role.tsxsrc/app/teams/[teamId]/hooks/use-create-role.tsx
📚 Learning: 2025-12-20T16:32:46.818Z
Learnt from: CR
Repo: drifter089/orgOS PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-20T16:32:46.818Z
Learning: Applies to src/app/teams/[teamId]/**/*.{ts,tsx} : Use auto-save system with debounce (2s delay) that serializes nodes/edges to tRPC mutation, with beforeunload sendBeacon fallback for unsaved changes
Applied to files:
src/app/teams/[teamId]/hooks/use-update-role.tsxsrc/app/teams/[teamId]/hooks/use-create-role.tsx
📚 Learning: 2025-12-20T16:32:46.818Z
Learnt from: CR
Repo: drifter089/orgOS PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-20T16:32:46.818Z
Learning: Applies to src/app/teams/[teamId]/**/*.{ts,tsx} : For new canvas node types: create component in teams/[teamId]/_components/, add to TeamNode union in types/canvas.ts, register in nodeTypes in team-canvas.tsx, and update serialization in canvas-serialization.ts
Applied to files:
src/app/teams/[teamId]/hooks/use-update-role.tsxsrc/app/teams/[teamId]/hooks/use-create-role.tsx
📚 Learning: 2025-12-20T22:12:00.566Z
Learnt from: CR
Repo: drifter089/orgOS PR: 0
File: GEMINI.md:0-0
Timestamp: 2025-12-20T22:12:00.566Z
Learning: Applies to src/app/teams/[teamId]/**/*.ts : Canvas changes must be debounced (2s) and saved via `editSession` logic to handle concurrent team edits safely
Applied to files:
src/app/teams/[teamId]/hooks/use-update-role.tsxsrc/app/teams/[teamId]/hooks/use-create-role.tsx
🧬 Code graph analysis (1)
src/server/api/routers/role.ts (1)
src/server/api/utils/cache-strategy.ts (2)
cacheStrategyWithTags(146-153)listCache(57-60)
🔇 Additional comments (3)
src/server/api/routers/role.ts (1)
9-13: Cache strategy imports correctly added.The imports for
cacheStrategyWithTags,invalidateCacheByTags, andlistCacheare properly integrated to support Prisma Accelerate caching with tag-based invalidation.Based on learnings, cache tag invalidation after mutations maintains consistency.
src/app/teams/[teamId]/hooks/use-update-role.tsx (1)
70-72: Cache invalidation consistency achieved.The addition of
role.getByTeamId.invalidate()mirrors the pattern introduced inuse-create-role.tsx, ensuring all role mutations (create, update, delete) maintain consistent cache coherency across both TanStack Query and Prisma Accelerate layers.src/app/teams/[teamId]/hooks/use-create-role.tsx (1)
187-189: Dual cache invalidation correctly implemented and consistent.The addition of
role.getByTeamId.invalidate()alongsideteam.getById.invalidate()is correct and follows the same pattern used inuseDeleteRole. Both mutations properly invalidate both cache layers (TanStack Query client-side cache and server-side via tags) to maintain consistency after role operations.
Summary
Improves cache invalidation consistency across role mutations by adding
invalidate()calls and Prisma Accelerate caching.Key Changes
role.getByTeamId.invalidate()touseCreateRoleanduseUpdateRoleonSuccess callbacksrole.getByTeamIdquery (60s TTL + 120s SWR)useDeleteRolefor consistencySummary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.