perf(platform): optimize RLS query initialization#533
Conversation
Replace authComponent.getAuthUser (2 cross-component DB queries) with getAuthUserIdentity (JWT-based, 0 DB queries) for RLS context setup. Parallelize getUserOrganizations and getUserTeamIds calls using Promise.all so the two adapter.findMany component queries run concurrently instead of sequentially. Reduces RLS setup from 4 sequential component queries to 2 parallel queries + 1 JWT read, fixing query timeout on listWebsites and similar RLS-wrapped queries.
…erable Convex reactive hooks can briefly see undefined properties during WebSocket reconnection. Classify these TypeErrors as transient so the error boundary retries instead of showing a crash screen.
…states Prevent typewriter animation from resetting when message status briefly drops back to "pending" during WebSocket reconnection. Track streaming keys in a ref and only clear them on terminal statuses (success/failed).
…nt-side extraction Embed fileName, fileType, and fileSize in the fileId italic markers written by the agent chat so the client can reconstruct structured FileAttachment objects without an extra server round-trip. Add extractFileAttachments() parser and wire it into useMessageProcessing.
Greptile SummaryThis PR implements three focused performance and stability improvements: RLS Query Optimization: Replaces Streaming Stability Fix: Implements a ref-based sticky File Attachment Metadata: Enriches internal file attachment markers with Confidence Score: 5/5
|
| Filename | Overview |
|---|---|
| services/platform/convex/lib/rls/helpers/query_with_rls.ts | Replaced getAuthenticatedUser with getAuthUserIdentity and parallelized org/team fetching with Promise.all() for performance |
| services/platform/convex/lib/rls/helpers/mutation_with_rls.ts | Applied same RLS optimization as queries - JWT-based auth and parallel data fetching |
| services/platform/app/features/chat/hooks/use-message-processing.ts | Added sticky isStreaming tracker using ref to prevent animation resets during reconnection, plus file attachment metadata extraction |
| services/platform/app/components/error-boundaries/boundaries/layout-error-boundary.tsx | Added TypeError detection for undefined property access during reconnection to transient error handling |
| services/platform/convex/lib/agent_chat/start_agent_chat.ts | Enriched file attachment markers with fileName, fileType, and fileSize metadata in all three attachment types |
Sequence Diagram
sequenceDiagram
participant Client
participant RLS Helper
participant JWT Identity
participant DB Queries
Client->>RLS Helper: Query/Mutation Request
Note over RLS Helper: OLD: getAuthenticatedUser
RLS Helper-->>DB Queries: authComponent.getAuthUser<br/>(2 cross-component queries)
DB Queries-->>RLS Helper: User data
RLS Helper-->>DB Queries: getUserOrganizations (sequential)
DB Queries-->>RLS Helper: Orgs
RLS Helper-->>DB Queries: getUserTeamIds (sequential)
DB Queries-->>RLS Helper: Teams
Note over RLS Helper: NEW: getAuthUserIdentity + Promise.all
RLS Helper->>JWT Identity: ctx.auth.getUserIdentity()<br/>(0 DB queries)
JWT Identity->>RLS Helper: User identity from JWT
par Parallel Fetching
RLS Helper->>DB Queries: getUserOrganizations
DB Queries->>RLS Helper: Orgs
and
RLS Helper->>DB Queries: getUserTeamIds
DB Queries->>RLS Helper: Teams
end
RLS Helper->>RLS Helper: Apply RLS rules
RLS Helper->>Client: Response with enforced access control
Last reviewed commit: 961c299
|
No actionable comments were generated in the recent review. 🎉 📝 WalkthroughWalkthroughThis PR extends error boundary transient error detection, enhances chat message processing with attachment extraction and streaming state persistence, refactors RLS helpers to use identity-based authentication with team ID data, and updates attachment reference formatting in markdown. Changes span error handling, chat features, authorization layer, and agent message building, introducing new utility functions, regex patterns for enriched attachment blocks, and consistent parameter passing of user team IDs across RLS rule evaluation paths. Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Comment |
Summary
getAuthenticatedUser(2 cross-component DB queries per call) withgetAuthUserIdentity(0 DB queries, uses cryptographically-validated JWT identity). Parallelizes organization and team ID fetching withPromise.all()across all RLS helpers (queryWithRLS,mutationWithRLS,zQueryWithRLS,zMutationWithRLS).isStreamingsticky across transient reconnection states using a ref-based tracker, preventing typewriter animation resets when the connection briefly drops to "pending" status.fileName,fileType, andfileSizemetadata so the client can extract structuredFileAttachmentobjects without additional server queries.Test plan
npx tsc --noEmitfromservices/platform/for type safetynpm run lint --workspace=@tale/platform🤖 Generated with Claude Code
Summary by CodeRabbit
Release Notes
New Features
Bug Fixes
Tests