Skip to content

Conversation

@drifter089
Copy link
Owner

@drifter089 drifter089 commented Dec 24, 2025

Summary

Improves cache invalidation consistency across role mutations by adding invalidate() calls and Prisma Accelerate caching.

Key Changes

  • Add role.getByTeamId.invalidate() to useCreateRole and useUpdateRole onSuccess callbacks
  • Add Prisma Accelerate cache strategy with tags to role.getByTeamId query (60s TTL + 120s SWR)
  • Aligns with existing pattern in useDeleteRole for consistency

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced cache management for team role operations. When creating or updating roles within your team, the system now properly refreshes all related cached data including team information and role listings, ensuring consistent and up-to-date information is always displayed across the application.

✏️ Tip: You can customize this high-level summary in your review settings.

@vercel
Copy link

vercel bot commented Dec 24, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
org-os Ready Ready Preview, Comment Dec 24, 2025 2:19pm

@coderabbitai
Copy link

coderabbitai bot commented Dec 24, 2025

📝 Walkthrough

Walkthrough

The 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

Cohort / File(s) Summary
Client-side cache invalidation
src/app/teams/[teamId]/hooks/use-create-role.tsx, src/app/teams/[teamId]/hooks/use-update-role.tsx
Expanded onSuccess cache invalidation to include utils.role.getByTeamId.invalidate({ teamId }) alongside existing team cache invalidation, ensuring role-by-team data remains fresh after mutations.
Server-side cache strategy
src/server/api/routers/role.ts
Added imports for cacheStrategyWithTags, invalidateCacheByTags, and listCache from cache-strategy utilities. Applied tag-based caching to the getByTeamId route via cacheStrategyWithTags(listCache, [\team_${input.teamId}`])` in Prisma query options.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Poem

🐰 Cache keys dance and tags align,
Roles and teams in perfect time,
When mutations stir the pot,
Invalidate the lot!
Fresh data blooms with every hop! 🌟

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately summarizes the main change: adding cache invalidation consistency to role mutations across multiple files and introducing Prisma caching.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch aurora

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a 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 to getByTeamId.

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 getByUser query (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

📥 Commits

Reviewing files that changed from the base of the PR and between 9077222 and 2efbc45.

📒 Files selected for processing (3)
  • src/app/teams/[teamId]/hooks/use-create-role.tsx
  • src/app/teams/[teamId]/hooks/use-update-role.tsx
  • src/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 ordering

Use TypeScript 5.9 with strict type checking for all frontend and backend code

Files:

  • src/server/api/routers/role.ts
  • src/app/teams/[teamId]/hooks/use-update-role.tsx
  • src/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 like getTeamAndVerifyAccess to verify access before operations
Be careful when modifying team save logic related to EditSession model, 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.tsx
  • src/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.tsx
  • src/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.tsx
  • src/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.ts
  • src/app/teams/[teamId]/hooks/use-update-role.tsx
  • src/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.ts
  • src/app/teams/[teamId]/hooks/use-update-role.tsx
  • src/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.ts
  • src/app/teams/[teamId]/hooks/use-update-role.tsx
  • src/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.ts
  • src/app/teams/[teamId]/hooks/use-update-role.tsx
  • src/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.ts
  • src/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.tsx
  • src/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.tsx
  • src/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.tsx
  • src/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.tsx
  • src/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.tsx
  • src/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, and listCache are 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 in use-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() alongside team.getById.invalidate() is correct and follows the same pattern used in useDeleteRole. Both mutations properly invalidate both cache layers (TanStack Query client-side cache and server-side via tags) to maintain consistency after role operations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants