-
Notifications
You must be signed in to change notification settings - Fork 1
refactor: consolidate cache invalidation and standardize user name functions #312
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.
|
📝 WalkthroughWalkthroughThis PR consolidates cache invalidation for dashboard mutations across multiple routers by introducing a centralized Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
📜 Recent review detailsConfiguration used: defaults Review profile: CHILL Plan: Pro 📒 Files selected for processing (13)
🧰 Additional context used📓 Path-based instructions (11)**/*.{ts,tsx}📄 CodeRabbit inference engine (GEMINI.md)
Files:
src/server/api/**/*.ts📄 CodeRabbit inference engine (CLAUDE.md)
Files:
**/*.{ts,tsx,js,jsx}📄 CodeRabbit inference engine (CLAUDE.md)
Files:
src/server/api/routers/**/*.ts📄 CodeRabbit inference engine (GEMINI.md)
Files:
src/hooks/**/*.ts{,x}📄 CodeRabbit inference engine (CLAUDE.md)
Files:
src/**/*.tsx📄 CodeRabbit inference engine (GEMINI.md)
Files:
src/**/*/*.tsx📄 CodeRabbit inference engine (GEMINI.md)
Files:
src/components/**/*.tsx📄 CodeRabbit inference engine (GEMINI.md)
Files:
**/*.tsx📄 CodeRabbit inference engine (GEMINI.md)
Files:
src/components/metric/**/*.tsx📄 CodeRabbit inference engine (CLAUDE.md)
Files:
**/*.md📄 CodeRabbit inference engine (GEMINI.md)
Files:
🧠 Learnings (28)📓 Common learnings📚 Learning: 2025-12-29T12:52:43.772ZApplied to files:
📚 Learning: 2025-12-29T12:52:42.935ZApplied to files:
📚 Learning: 2025-12-29T12:52:42.935ZApplied to files:
📚 Learning: 2025-12-29T12:52:43.772ZApplied to files:
📚 Learning: 2025-12-29T12:52:43.772ZApplied to files:
📚 Learning: 2025-12-29T12:52:42.935ZApplied to files:
📚 Learning: 2025-12-29T12:52:43.772ZApplied to files:
📚 Learning: 2025-12-29T12:52:43.772ZApplied to files:
📚 Learning: 2025-12-29T12:52:42.935ZApplied to files:
📚 Learning: 2025-12-29T12:52:42.935ZApplied to files:
📚 Learning: 2025-12-29T12:52:43.772ZApplied to files:
📚 Learning: 2025-12-29T12:52:42.935ZApplied to files:
📚 Learning: 2025-12-29T12:52:42.935ZApplied to files:
📚 Learning: 2025-12-20T22:12:00.576ZApplied to files:
📚 Learning: 2025-12-29T12:52:43.772ZApplied to files:
📚 Learning: 2025-12-20T22:12:00.576ZApplied to files:
📚 Learning: 2025-12-29T12:52:42.935ZApplied to files:
📚 Learning: 2025-12-20T22:12:00.576ZApplied to files:
📚 Learning: 2025-12-29T12:52:43.772ZApplied to files:
📚 Learning: 2025-12-29T12:52:43.772ZApplied to files:
📚 Learning: 2025-12-29T12:52:42.935ZApplied to files:
📚 Learning: 2025-12-29T12:52:43.772ZApplied to files:
📚 Learning: 2025-12-29T12:52:42.935ZApplied to files:
📚 Learning: 2025-12-29T12:52:43.772ZApplied to files:
📚 Learning: 2025-12-20T22:12:00.576ZApplied to files:
📚 Learning: 2025-12-29T12:52:43.772ZApplied to files:
📚 Learning: 2025-12-20T22:12:00.576ZApplied to files:
🧬 Code graph analysis (9)src/server/api/utils/cache-strategy.ts (1)
src/server/api/routers/role.ts (1)
src/server/api/services/transformation/chart-generator.ts (2)
src/hooks/use-optimistic-role-update.ts (1)
src/server/api/routers/manual-metric.ts (1)
src/components/metric/role-assignment.tsx (1)
src/server/api/routers/metric.ts (1)
src/server/api/routers/pipeline.ts (2)
src/server/api/routers/dashboard.ts (1)
🔇 Additional comments (14)
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
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/server/api/routers/role.ts (1)
118-121: Add organization-level dashboard cache invalidation to all role mutations.Role mutations currently invalidate
team_${teamId}anddashboard_team_${teamId}, but miss the organization-level dashboard cache tagdashboard_org_${organizationId}. Since dashboard queries use both org-level and team-level cache tags, and roles affect dashboard visibility, the org-level tag must also be invalidated.Current pattern at lines 118-121, 209-212, and 230-233:
await invalidateCacheByTags(ctx.db, [ `team_${input.teamId}`, `dashboard_team_${input.teamId}`, ]);Required pattern:
await invalidateCacheByTags(ctx.db, [ `team_${input.teamId}`, `dashboard_org_${ctx.workspace.organizationId}`, `dashboard_team_${input.teamId}`, ]);The
team_tag cannot be removed—it's required forrole.getByTeamIdcache consistency, whichinvalidateDashboardCachedoes not handle.
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (13)
CLAUDE.mdsrc/components/metric/role-assignment.tsxsrc/hooks/use-optimistic-role-update.tssrc/lib/helpers/get-user-name.tssrc/server/api/routers/dashboard.tssrc/server/api/routers/manual-metric.tssrc/server/api/routers/metric.tssrc/server/api/routers/pipeline.tssrc/server/api/routers/role.tssrc/server/api/services/transformation/chart-generator.tssrc/server/api/utils/cache-strategy.tssrc/server/api/utils/get-user-display-name.tssrc/server/api/utils/organization-members.ts
🧰 Additional context used
📓 Path-based instructions (11)
**/*.{ts,tsx}
📄 CodeRabbit inference engine (GEMINI.md)
Use TypeScript 5.9 with strict type checking for all frontend and backend code
Use tRPC dual API pattern: in Server Components, make direct calls using
import { api } from '@/trpc/server'; in Client Components, use React hooks with TanStack Query usingimport { api } from '@/trpc/react'. Server calls are 10x faster than client-side queries.
Files:
src/server/api/utils/cache-strategy.tssrc/server/api/utils/get-user-display-name.tssrc/server/api/routers/role.tssrc/server/api/services/transformation/chart-generator.tssrc/lib/helpers/get-user-name.tssrc/hooks/use-optimistic-role-update.tssrc/server/api/routers/manual-metric.tssrc/server/api/utils/organization-members.tssrc/components/metric/role-assignment.tsxsrc/server/api/routers/metric.tssrc/server/api/routers/pipeline.tssrc/server/api/routers/dashboard.ts
src/server/api/**/*.ts
📄 CodeRabbit inference engine (CLAUDE.md)
For tRPC cache invalidation after mutations, use the
invalidateCacheByTags()utility with appropriate cache tags (e.g.,team_${teamId}) to ensure cache consistency.
Files:
src/server/api/utils/cache-strategy.tssrc/server/api/utils/get-user-display-name.tssrc/server/api/routers/role.tssrc/server/api/services/transformation/chart-generator.tssrc/server/api/routers/manual-metric.tssrc/server/api/utils/organization-members.tssrc/server/api/routers/metric.tssrc/server/api/routers/pipeline.tssrc/server/api/routers/dashboard.ts
**/*.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (CLAUDE.md)
Use pre-commit hooks (Husky + lint-staged) which automatically run ESLint auto-fix and Prettier formatting on staged files. Configure import sorting with
@trivago/prettier-plugin-sort-importsusing inline type imports.
Files:
src/server/api/utils/cache-strategy.tssrc/server/api/utils/get-user-display-name.tssrc/server/api/routers/role.tssrc/server/api/services/transformation/chart-generator.tssrc/lib/helpers/get-user-name.tssrc/hooks/use-optimistic-role-update.tssrc/server/api/routers/manual-metric.tssrc/server/api/utils/organization-members.tssrc/components/metric/role-assignment.tsxsrc/server/api/routers/metric.tssrc/server/api/routers/pipeline.tssrc/server/api/routers/dashboard.ts
src/server/api/routers/**/*.ts
📄 CodeRabbit inference engine (GEMINI.md)
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 editingAlways use
protectedProcedureorworkspaceProcedurefor tRPC routes, and include authorization checks using helpers fromsrc/server/api/utils/authorization.ts(getMetricAndVerifyAccess, getRoleAndVerifyAccess, getTeamAndVerifyAccess) to verify resources belong to the user's organization.
Files:
src/server/api/routers/role.tssrc/server/api/routers/manual-metric.tssrc/server/api/routers/metric.tssrc/server/api/routers/pipeline.tssrc/server/api/routers/dashboard.ts
src/hooks/**/*.ts{,x}
📄 CodeRabbit inference engine (CLAUDE.md)
src/hooks/**/*.ts{,x}: For role mutations with TanStack Query, implement optimistic updates using the pattern: 1) onMutate with optimistic update, 2) setData with server response (critical - use server response before invalidate), 3) invalidate for background refresh, 4) onError with rollback to previousData. Use the shareduse-optimistic-role-update.tshook.
For dashboard role-metric assignments, update both the role cache (role.getByTeamId) and dashboard cache (dashboard.getDashboardCharts) optimistically during mutations to maintain consistency across both views.
Files:
src/hooks/use-optimistic-role-update.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/components/metric/role-assignment.tsx
src/**/*/*.tsx
📄 CodeRabbit inference engine (GEMINI.md)
Client Components must use
import { api } from '@/trpc/react'for standard HTTP/Hooks wrapper
Files:
src/components/metric/role-assignment.tsx
src/components/**/*.tsx
📄 CodeRabbit inference engine (GEMINI.md)
Place colocated components in
_components/folders next to their parent component
Files:
src/components/metric/role-assignment.tsx
**/*.tsx
📄 CodeRabbit inference engine (GEMINI.md)
Use Tailwind CSS 4 for styling with shadcn/ui and Radix UI primitive components
Files:
src/components/metric/role-assignment.tsx
src/components/metric/**/*.tsx
📄 CodeRabbit inference engine (CLAUDE.md)
Extract shared dashboard card patterns by consolidating
dashboard-metric-card.tsxandpublic-dashboard-metric-card.tsxinto a single component with areadOnlymode instead of maintaining separate components.
Files:
src/components/metric/role-assignment.tsx
**/*.md
📄 CodeRabbit inference engine (GEMINI.md)
Do not create random
.mddocumentation files unless explicitly asked; use CLAUDE.md or GEMINI.md for reference documentationDo not create random .md documentation files when implementing features. Provide explanations in chat messages, add comments in code where necessary, and only update existing documentation (CLAUDE.md, README.md) if required. Only create documentation files if explicitly requested.
Files:
CLAUDE.md
🧠 Learnings (28)
📓 Common learnings
Learnt from: CR
Repo: drifter089/orgOS PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-29T12:52:42.935Z
Learning: Applies to src/app/dashboard/[teamId]/**/*.{ts,tsx} : Dashboard cache updates for role-metric assignments must update both `role.getByTeamId` and `dashboard.getDashboardCharts` caches during mutations. Use onMutate for optimistic updates on both caches, then invalidate both on success.
Learnt from: CR
Repo: drifter089/orgOS PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-29T12:52:43.772Z
Learning: Applies to src/hooks/**/*.ts{,x} : For dashboard role-metric assignments, update both the role cache (`role.getByTeamId`) and dashboard cache (`dashboard.getDashboardCharts`) optimistically during mutations to maintain consistency across both views.
Learnt from: CR
Repo: drifter089/orgOS PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-29T12:52:42.935Z
Learning: Applies to src/app/**/*role*mutation*.{ts,tsx} : For role mutations, use cache pipeline with two operations: (1) onMutate for optimistic update, (2) onSuccess with both setData(updatedRole) using server response AND invalidate() for background refresh. Always use server response data in setData before invalidate to ensure Prisma Accelerate cache consistency.
Learnt from: CR
Repo: drifter089/orgOS PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-29T12:52:42.935Z
Learning: Applies to src/server/api/routers/**/*.ts : After mutations, invalidate cache tags using `invalidateCacheByTags(ctx.db, [``tag_${id}``])` to trigger background cache updates with Prisma Accelerate.
Learnt from: CR
Repo: drifter089/orgOS PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-29T12:52:43.772Z
Learning: Applies to src/server/api/**/*.ts : For tRPC cache invalidation after mutations, use the `invalidateCacheByTags()` utility with appropriate cache tags (e.g., `team_${teamId}`) to ensure cache consistency.
📚 Learning: 2025-12-29T12:52:43.772Z
Learnt from: CR
Repo: drifter089/orgOS PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-29T12:52:43.772Z
Learning: Applies to src/server/api/**/*.ts : For tRPC cache invalidation after mutations, use the `invalidateCacheByTags()` utility with appropriate cache tags (e.g., `team_${teamId}`) to ensure cache consistency.
Applied to files:
src/server/api/utils/cache-strategy.tssrc/server/api/routers/role.tssrc/server/api/services/transformation/chart-generator.tssrc/server/api/routers/manual-metric.tssrc/server/api/routers/metric.tssrc/server/api/routers/pipeline.tssrc/server/api/routers/dashboard.ts
📚 Learning: 2025-12-29T12:52:42.935Z
Learnt from: CR
Repo: drifter089/orgOS PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-29T12:52:42.935Z
Learning: Applies to src/app/dashboard/[teamId]/**/*.{ts,tsx} : Dashboard cache updates for role-metric assignments must update both `role.getByTeamId` and `dashboard.getDashboardCharts` caches during mutations. Use onMutate for optimistic updates on both caches, then invalidate both on success.
Applied to files:
src/server/api/utils/cache-strategy.tssrc/server/api/routers/role.tssrc/server/api/services/transformation/chart-generator.tssrc/hooks/use-optimistic-role-update.tssrc/server/api/routers/manual-metric.tssrc/server/api/utils/organization-members.tssrc/components/metric/role-assignment.tsxCLAUDE.mdsrc/server/api/routers/metric.tssrc/server/api/routers/pipeline.tssrc/server/api/routers/dashboard.ts
📚 Learning: 2025-12-29T12:52:42.935Z
Learnt from: CR
Repo: drifter089/orgOS PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-29T12:52:42.935Z
Learning: Applies to src/server/api/routers/**/*.ts : After mutations, invalidate cache tags using `invalidateCacheByTags(ctx.db, [``tag_${id}``])` to trigger background cache updates with Prisma Accelerate.
Applied to files:
src/server/api/utils/cache-strategy.tssrc/server/api/routers/role.tssrc/server/api/services/transformation/chart-generator.tssrc/server/api/routers/manual-metric.tssrc/server/api/routers/metric.tssrc/server/api/routers/pipeline.tssrc/server/api/routers/dashboard.ts
📚 Learning: 2025-12-29T12:52:43.772Z
Learnt from: CR
Repo: drifter089/orgOS PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-29T12:52:43.772Z
Learning: Applies to src/hooks/**/*.ts{,x} : For dashboard role-metric assignments, update both the role cache (`role.getByTeamId`) and dashboard cache (`dashboard.getDashboardCharts`) optimistically during mutations to maintain consistency across both views.
Applied to files:
src/server/api/utils/cache-strategy.tssrc/server/api/routers/role.tssrc/server/api/services/transformation/chart-generator.tssrc/hooks/use-optimistic-role-update.tssrc/server/api/routers/manual-metric.tssrc/server/api/utils/organization-members.tssrc/components/metric/role-assignment.tsxCLAUDE.mdsrc/server/api/routers/metric.tssrc/server/api/routers/pipeline.tssrc/server/api/routers/dashboard.ts
📚 Learning: 2025-12-29T12:52:43.772Z
Learnt from: CR
Repo: drifter089/orgOS PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-29T12:52:43.772Z
Learning: Applies to src/app/teams/[teamId]/**/*.tsx : For canvas node types that reference other entities (e.g., role nodes), store only the ID in node data and fetch display data from TanStack Query cache using dedicated hooks to avoid data duplication and ensure cache consistency.
Applied to files:
src/server/api/utils/cache-strategy.tssrc/server/api/services/transformation/chart-generator.tssrc/server/api/routers/manual-metric.tssrc/server/api/utils/organization-members.tsCLAUDE.mdsrc/server/api/routers/metric.tssrc/server/api/routers/pipeline.tssrc/server/api/routers/dashboard.ts
📚 Learning: 2025-12-29T12:52:42.935Z
Learnt from: CR
Repo: drifter089/orgOS PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-29T12:52:42.935Z
Learning: Applies to src/app/teams/[teamId]/**/*.{ts,tsx} : Canvas auto-save system: Changes trigger markDirty() → Debounce 2s → serializeNodes/Edges → tRPC mutation. Include beforeunload sendBeacon fallback for unsaved changes.
Applied to files:
src/server/api/utils/cache-strategy.tssrc/server/api/routers/pipeline.tssrc/server/api/routers/dashboard.ts
📚 Learning: 2025-12-29T12:52:43.772Z
Learnt from: CR
Repo: drifter089/orgOS PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-29T12:52:43.772Z
Learning: Applies to src/app/teams/[teamId]/**/*.ts{,x} : Implement auto-save for canvas changes using the pattern: Canvas changes → markDirty() → Debounce 2s → serializeNodes/Edges → tRPC mutation, with beforeunload sendBeacon as fallback.
Applied to files:
src/server/api/utils/cache-strategy.tssrc/server/api/routers/pipeline.tssrc/server/api/routers/dashboard.ts
📚 Learning: 2025-12-29T12:52:43.772Z
Learnt from: CR
Repo: drifter089/orgOS PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-29T12:52:43.772Z
Learning: Applies to src/app/teams/[teamId]/_components/**/*.tsx : Extract shared role node patterns by consolidating `role-node.tsx` and `public-role-node.tsx` (75% identical) into a single `RoleNodeTemplate` component with an `isEditable` prop.
Applied to files:
src/server/api/routers/role.tssrc/hooks/use-optimistic-role-update.tssrc/server/api/utils/organization-members.tssrc/components/metric/role-assignment.tsxCLAUDE.md
📚 Learning: 2025-12-29T12:52:42.935Z
Learnt from: CR
Repo: drifter089/orgOS PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-29T12:52:42.935Z
Learning: Applies to src/app/teams/[teamId]/**/*.{ts,tsx} : Cache-first node system: Role nodes store only `roleId` in node.data. Display data must be fetched from TanStack Query cache using the `useRoleData()` hook which queries the `role.getByTeamId` procedure.
Applied to files:
src/server/api/routers/role.tssrc/hooks/use-optimistic-role-update.tssrc/server/api/utils/organization-members.tsCLAUDE.mdsrc/server/api/routers/pipeline.tssrc/server/api/routers/dashboard.ts
📚 Learning: 2025-12-29T12:52:42.935Z
Learnt from: CR
Repo: drifter089/orgOS PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-29T12:52:42.935Z
Learning: Applies to src/hooks/use-optimistic-role-update.ts : The `use-optimistic-role-update` hook provides shared logic for all role mutations with proper cache layer handling for TanStack Query and Prisma Accelerate. Use this hook in canvas-specific wrappers to add markDirty side effects.
Applied to files:
src/server/api/routers/role.tssrc/hooks/use-optimistic-role-update.tssrc/components/metric/role-assignment.tsx
📚 Learning: 2025-12-29T12:52:43.772Z
Learnt from: CR
Repo: drifter089/orgOS PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-29T12:52:43.772Z
Learning: Applies to src/hooks/**/*.ts{,x} : For role mutations with TanStack Query, implement optimistic updates using the pattern: 1) onMutate with optimistic update, 2) setData with server response (critical - use server response before invalidate), 3) invalidate for background refresh, 4) onError with rollback to previousData. Use the shared `use-optimistic-role-update.ts` hook.
Applied to files:
src/server/api/routers/role.tssrc/hooks/use-optimistic-role-update.tssrc/components/metric/role-assignment.tsx
📚 Learning: 2025-12-29T12:52:42.935Z
Learnt from: CR
Repo: drifter089/orgOS PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-29T12:52:42.935Z
Learning: Applies to src/app/**/*role*mutation*.{ts,tsx} : For role mutations, use cache pipeline with two operations: (1) onMutate for optimistic update, (2) onSuccess with both setData(updatedRole) using server response AND invalidate() for background refresh. Always use server response data in setData before invalidate to ensure Prisma Accelerate cache consistency.
Applied to files:
src/server/api/routers/role.tssrc/hooks/use-optimistic-role-update.tssrc/server/api/routers/metric.tssrc/server/api/routers/pipeline.tssrc/server/api/routers/dashboard.ts
📚 Learning: 2025-12-29T12:52:42.935Z
Learnt from: CR
Repo: drifter089/orgOS PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-29T12:52:42.935Z
Learning: Applies to src/app/teams/[teamId]/_components/role-node.tsx,src/app/teams/[teamId]/_components/public-role-node.tsx : These role node components are 75% identical and should be consolidated. Extract shared `RoleNodeTemplate` component with `isEditable` prop to DRY up the code.
Applied to files:
src/server/api/routers/role.tssrc/server/api/utils/organization-members.tssrc/components/metric/role-assignment.tsx
📚 Learning: 2025-12-20T22:12:00.576Z
Learnt from: CR
Repo: drifter089/orgOS PR: 0
File: GEMINI.md:0-0
Timestamp: 2025-12-20T22:12:00.576Z
Learning: Applies to src/lib/metrics/**/*.ts : Metric transformation logic should be organized in `src/lib/metrics/` to support the 3-stage pipeline: Ingestion → Aggregation → Visualization
Applied to files:
src/server/api/services/transformation/chart-generator.tssrc/server/api/routers/manual-metric.tssrc/server/api/routers/metric.tssrc/server/api/routers/pipeline.ts
📚 Learning: 2025-12-29T12:52:43.772Z
Learnt from: CR
Repo: drifter089/orgOS PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-29T12:52:43.772Z
Learning: Applies to **/*.{ts,tsx} : Use tRPC dual API pattern: in Server Components, make direct calls using `import { api } from '@/trpc/server'`; in Client Components, use React hooks with TanStack Query using `import { api } from '@/trpc/react'`. Server calls are 10x faster than client-side queries.
Applied to files:
src/server/api/services/transformation/chart-generator.ts
📚 Learning: 2025-12-20T22:12:00.576Z
Learnt from: CR
Repo: drifter089/orgOS PR: 0
File: GEMINI.md:0-0
Timestamp: 2025-12-20T22:12:00.576Z
Learning: Applies to src/app/**/*.ts : Server Components must use `import { api } from '@/trpc/server'` for direct DB calls without HTTP overhead
Applied to files:
src/server/api/services/transformation/chart-generator.ts
📚 Learning: 2025-12-29T12:52:42.935Z
Learnt from: CR
Repo: drifter089/orgOS PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-29T12:52:42.935Z
Learning: Applies to **/*.{ts,tsx} : For client components using tRPC, use the React Query pattern with `import { api } from '@/trpc/react'` and access data via `api.[router].[procedure].useQuery()`. For server components, use direct calls with `import { api } from '@/trpc/server'` and await the result.
Applied to files:
src/server/api/services/transformation/chart-generator.tssrc/server/api/routers/manual-metric.tssrc/server/api/routers/pipeline.ts
📚 Learning: 2025-12-20T22:12:00.576Z
Learnt from: CR
Repo: drifter089/orgOS PR: 0
File: GEMINI.md:0-0
Timestamp: 2025-12-20T22:12:00.576Z
Learning: The Metrics Pipeline processes data through 3 stages: DataIngestionTransformer (Raw API → MetricDataPoint), ChartTransformer (MetricDataPoint → Chart Config), and Visualization (Chart Config → Recharts UI)
Applied to files:
src/server/api/services/transformation/chart-generator.tssrc/server/api/routers/pipeline.ts
📚 Learning: 2025-12-29T12:52:43.772Z
Learnt from: CR
Repo: drifter089/orgOS PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-29T12:52:43.772Z
Learning: The metrics pipeline follows a three-stage transformation: 1) API → DataPoints via DataIngestionTransformer, 2) DataPoints → ChartConfig via ChartTransformer, 3) ChartConfig → UI via DashboardMetricChart. Use AI-generated transformers for stage 1 and 2.
Applied to files:
src/server/api/services/transformation/chart-generator.tssrc/server/api/routers/pipeline.ts
📚 Learning: 2025-12-29T12:52:43.772Z
Learnt from: CR
Repo: drifter089/orgOS PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-29T12:52:43.772Z
Learning: Applies to src/components/member/**/*.tsx : Use the shared `MembersList` component from `src/components/member/member-list.tsx` and `getMemberDisplayInfo()` utility for consistent member display logic (initials/name) across canvas sidebar and org page.
Applied to files:
src/lib/helpers/get-user-name.tssrc/hooks/use-optimistic-role-update.tssrc/server/api/utils/organization-members.tssrc/components/metric/role-assignment.tsxCLAUDE.md
📚 Learning: 2025-12-29T12:52:42.935Z
Learnt from: CR
Repo: drifter089/orgOS PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-29T12:52:42.935Z
Learning: Applies to src/components/dashboard-metric-card.tsx,src/app/dashboard/[teamId]/_components/public-dashboard-metric-card.tsx : Dashboard metric cards are duplicated with public variant. Consolidate into single component with `readOnly` mode prop instead of maintaining separate components.
Applied to files:
src/server/api/routers/manual-metric.tsCLAUDE.mdsrc/server/api/routers/metric.tssrc/server/api/routers/dashboard.ts
📚 Learning: 2025-12-29T12:52:43.772Z
Learnt from: CR
Repo: drifter089/orgOS PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-29T12:52:43.772Z
Learning: Applies to src/components/metric/**/*.tsx : Extract shared dashboard card patterns by consolidating `dashboard-metric-card.tsx` and `public-dashboard-metric-card.tsx` into a single component with a `readOnly` mode instead of maintaining separate components.
Applied to files:
src/server/api/routers/manual-metric.tsCLAUDE.mdsrc/server/api/routers/metric.tssrc/server/api/routers/dashboard.ts
📚 Learning: 2025-12-29T12:52:42.935Z
Learnt from: CR
Repo: drifter089/orgOS PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-29T12:52:42.935Z
Learning: Applies to src/server/api/routers/**/*.ts : When adding new tRPC routes, use `protectedProcedure` or `workspaceProcedure` and always verify resource belongs to user's organization using authorization helpers (getMetricAndVerifyAccess, getRoleAndVerifyAccess, getTeamAndVerifyAccess) from '@/server/api/utils/authorization'.
Applied to files:
src/server/api/routers/manual-metric.tssrc/server/api/routers/metric.tssrc/server/api/routers/pipeline.ts
📚 Learning: 2025-12-29T12:52:43.772Z
Learnt from: CR
Repo: drifter089/orgOS PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-29T12:52:43.772Z
Learning: Applies to src/server/api/routers/**/*.ts : Always use `protectedProcedure` or `workspaceProcedure` for tRPC routes, and include authorization checks using helpers from `src/server/api/utils/authorization.ts` (getMetricAndVerifyAccess, getRoleAndVerifyAccess, getTeamAndVerifyAccess) to verify resources belong to the user's organization.
Applied to files:
src/server/api/routers/manual-metric.tsCLAUDE.mdsrc/server/api/routers/pipeline.ts
📚 Learning: 2025-12-20T22:12:00.576Z
Learnt from: CR
Repo: drifter089/orgOS PR: 0
File: GEMINI.md:0-0
Timestamp: 2025-12-20T22:12:00.576Z
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/server/api/utils/organization-members.ts
📚 Learning: 2025-12-29T12:52:43.772Z
Learnt from: CR
Repo: drifter089/orgOS PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-29T12:52:43.772Z
Learning: Applies to src/app/metric/_components/**/*.tsx : Consolidate nearly identical metric dialog wrappers (5 files) by using a factory pattern to reduce duplication across different provider implementations.
Applied to files:
src/components/metric/role-assignment.tsx
📚 Learning: 2025-12-20T22:12:00.576Z
Learnt from: CR
Repo: drifter089/orgOS PR: 0
File: GEMINI.md:0-0
Timestamp: 2025-12-20T22:12:00.576Z
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/components/metric/role-assignment.tsxCLAUDE.md
🧬 Code graph analysis (9)
src/server/api/utils/cache-strategy.ts (1)
src/server/db.ts (1)
db(26-26)
src/server/api/routers/role.ts (1)
src/server/api/utils/get-user-display-name.ts (1)
fetchUserDisplayName(14-26)
src/server/api/services/transformation/chart-generator.ts (2)
src/server/api/utils/cache-strategy.ts (1)
invalidateDashboardCache(197-206)src/server/db.ts (1)
db(26-26)
src/hooks/use-optimistic-role-update.ts (1)
src/lib/helpers/get-user-name.ts (1)
getUserDisplayName(7-17)
src/server/api/routers/manual-metric.ts (1)
src/server/api/utils/cache-strategy.ts (1)
invalidateDashboardCache(197-206)
src/components/metric/role-assignment.tsx (1)
src/lib/helpers/get-user-name.ts (1)
getUserDisplayName(7-17)
src/server/api/routers/metric.ts (1)
src/server/api/utils/cache-strategy.ts (1)
invalidateDashboardCache(197-206)
src/server/api/routers/pipeline.ts (2)
src/server/api/utils/cache-strategy.ts (1)
invalidateDashboardCache(197-206)src/server/db.ts (1)
db(26-26)
src/server/api/routers/dashboard.ts (1)
src/server/api/utils/cache-strategy.ts (1)
invalidateDashboardCache(197-206)
🔇 Additional comments (14)
src/server/api/utils/organization-members.ts (2)
136-153: LGTM: Clean helper extraction.The
enrichRoleWithNamehelper consolidates the role enrichment logic nicely. The fallback pattern usingUser ${role.assignedUserId.substring(0, 8)}provides a reasonable default when a user ID isn't found in the member map.
155-171: LGTM: Efficient conditional fetching.The
getMemberNameMapIfNeededhelper avoids unnecessary API calls by checking if any roles need enrichment first. This is a good performance optimization.src/server/api/routers/role.ts (1)
15-15: LGTM: Consistent rename tofetchUserDisplayName.The function rename aligns with the server-side naming convention established in this PR.
Also applies to: 99-99, 172-174
src/server/api/routers/manual-metric.ts (1)
17-17: LGTM: Clean adoption of centralized cache invalidation.The migration to
invalidateDashboardCacheconsolidates the cache invalidation pattern and improves maintainability.Also applies to: 92-96
src/hooks/use-optimistic-role-update.ts (1)
5-5: LGTM: Standardized user name resolution.The migration to the shared
getUserDisplayNamehelper eliminates code duplication and ensures consistent user name resolution across client components.Also applies to: 51-51
src/server/api/utils/cache-strategy.ts (1)
185-206: LGTM: Well-designed cache invalidation helper.The
invalidateDashboardCachefunction successfully consolidates the repeated pattern of building dashboard cache tags. The implementation correctly constructs organization-level and optional team-level tags before delegating toinvalidateCacheByTags.src/lib/helpers/get-user-name.ts (1)
1-17: LGTM: Consistent naming convention.The rename from
getUserNametogetUserDisplayNameestablishes clear naming consistency between client-side (synchronous lookup) and server-side (asyncfetchUserDisplayName) user name resolution.src/server/api/routers/pipeline.ts (1)
10-10: LGTM: Comprehensive cache invalidation migration.All pipeline mutation endpoints have been consistently updated to use
invalidateDashboardCache, eliminating manual tag construction and improving maintainability across the router.Also applies to: 53-53, 160-164, 190-194, 236-240, 297-301
src/server/api/utils/get-user-display-name.ts (1)
14-26: LGTM: Clear server-side naming.The rename to
fetchUserDisplayNameclearly distinguishes the async server-side WorkOS lookup from the client-side synchronous helper (getUserDisplayName), making the API intent more explicit.src/server/api/services/transformation/chart-generator.ts (1)
6-6: LGTM! Cache invalidation successfully consolidated.The replacement of
invalidateCacheByTagswithinvalidateDashboardCachecleanly centralizes the dashboard cache invalidation pattern. Both call sites correctly passdb,organizationId, andteamId(nullable), matching the utility's signature. This eliminates manual tag construction (dashboard_org_${organizationId},dashboard_team_${teamId}) and reduces duplication across the codebase.Also applies to: 268-272, 472-476
src/components/metric/role-assignment.tsx (1)
27-27: LGTM! User display name function successfully standardized.The rename from
getUserNametogetUserDisplayNameimproves clarity and aligns with the standardized naming convention across the codebase (client-side:getUserDisplayName, server-side:fetchUserDisplayName). The function signature and call site remain correct, with no behavioral changes.Also applies to: 140-143
src/server/api/routers/dashboard.ts (1)
9-9: LGTM! Dashboard cache invalidation successfully consolidated.The migration to
invalidateDashboardCachesimplifies the mutation by replacing manual cache tag construction with a centralized utility. The call correctly passesctx.db,ctx.workspace.organizationId, andexisting.metric?.teamId(which properly handles optional teamId using optional chaining).Also applies to: 166-170
src/server/api/routers/metric.ts (1)
12-12: LGTM! All metric mutations correctly use consolidated cache invalidation.The three mutation endpoints (
create,update,delete) have been successfully migrated to useinvalidateDashboardCache. Each call site correctly handles optional/nullableteamIdvalues and ensures cache consistency after mutations. This consolidation aligns with the established cache invalidation pattern for Prisma Accelerate.Based on learnings: cache invalidation after mutations is critical for Prisma Accelerate cache consistency.
Also applies to: 201-205, 240-244, 271-275
CLAUDE.md (1)
373-397: LGTM! Documentation accurately reflects the refactoring.The updates correctly document:
- The new
invalidateDashboardCachepattern for tRPC mutations (lines 373-378)- Consolidated component patterns including
MembersList(lines 380-386)- Role enrichment utilities in
organization-members.ts(lines 387-392)- Standardized user display name functions: client-side
getUserDisplayNameand server-sidefetchUserDisplayName(lines 393-397)This provides clear guidance for future development and ensures consistency across the codebase.
Summary
Consolidates repeated cache invalidation patterns into a shared utility and standardizes user name function naming across the codebase.
Key Changes
invalidateDashboardCache()utility to cache-strategy.tsgetUserDisplayName(), server-sidefetchUserDisplayName()Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.