⚡ Bolt: batch MCP OAuth token database lookups to fix N+1 query - #170
⚡ Bolt: batch MCP OAuth token database lookups to fix N+1 query#170Donach wants to merge 1 commit into
Conversation
Replaces the N+1 database queries for MCP server OAuth tokens with a single batched query using Drizzle's `inArray` inside `apps/agor-daemon/src/register-hooks.ts`. Tokens are now pre-fetched and stored in an O(1) in-memory Map using a compound key of `<server_id>:<user_id|shared>`, preserving both shared-mode and per-user token isolation.
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
💡 What:
Replaces the
Promise.all(context.result.map(injectToken))approach for fetching MCP OAuth tokens inregister-hooks.tswith a batched query. IntroducesgetTokensForServersto theUserMCPOAuthTokenRepositoryusing Drizzle'sinArrayto fetch all tokens simultaneously, placing them in an in-memory Map for O(1) synchronous lookup.🎯 Why:
Previously, rendering a list of MCP servers (like in the UI or during orchestration) triggered an individual database
getToken()call per server for OAuth tokens. This resulted in an N+1 query problem, creating unnecessary database latency.📊 Impact:
Reduces database round-trips from O(N) to O(1) when fetching lists of OAuth-enabled MCP servers. Substantially improves response latency for large server lists, and minimizes load on the SQLite / libSQL database.
🔬 Measurement:
Run
pnpm -w agor session listor load the workspace UI with multiple OAuth-authenticated MCP servers configured. Verify that the tokens resolve properly (eitherper_userorshared) and that database logs show a single query fetching all required tokens via$ininstead of iterative individual queries.PR created automatically by Jules for task 6178228255922363110 started by @Donach