Skip to content

perf(convex): deduplicate auth fetches in RLS helpers#414

Merged
Israeltheminer merged 1 commit into
mainfrom
fix/rls-deduplicate-auth
Feb 9, 2026
Merged

perf(convex): deduplicate auth fetches in RLS helpers#414
Israeltheminer merged 1 commit into
mainfrom
fix/rls-deduplicate-auth

Conversation

@Israeltheminer

@Israeltheminer Israeltheminer commented Feb 9, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Fetches user and userOrganizations once in mutationWithRLS/queryWithRLS wrappers
  • Passes pre-fetched data to rlsRules() via optional prefetchedData parameter
  • Eliminates redundant getAuthenticatedUser() and getUserOrganizations() calls on every RLS-wrapped query/mutation

Test plan

  • Verify existing RLS-protected queries/mutations still work correctly
  • Confirm no duplicate auth fetches in Convex function logs

Summary by CodeRabbit

  • Refactor
    • Optimized authentication data fetching by pre-fetching user and organization information once and reusing it across related operations, eliminating redundant database calls.

Fetch user and organization data once in mutation/query wrappers
and pass to rlsRules via optional prefetchedData parameter,
eliminating redundant auth lookups on every RLS-wrapped call.
@coderabbitai

coderabbitai Bot commented Feb 9, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

The changes refactor RLS (Row-Level Security) rule computation by modifying the call pattern in two helper files to pre-fetch authentication data once before invoking rlsRules. Instead of rlsRules fetching user and organization data internally, both mutation_with_rls.ts and query_with_rls.ts now retrieve this data upfront and pass it as an optional parameter to rlsRules. The rlsRules function signature is updated to accept optional pre-fetched data, with fallback logic to fetch data itself if not provided. This eliminates potential duplicate data fetches within rlsRules.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'perf(convex): deduplicate auth fetches in RLS helpers' accurately and concisely describes the main optimization: eliminating duplicate authentication data fetches in RLS helper functions by prefetching once and passing the data as a parameter.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 fix/rls-deduplicate-auth

No actionable comments were generated in the recent review. 🎉


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

@Israeltheminer Israeltheminer merged commit cbcfb94 into main Feb 9, 2026
5 checks passed
@Israeltheminer Israeltheminer deleted the fix/rls-deduplicate-auth branch February 9, 2026 15:40
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.

1 participant