⚡ Bolt: [Batch FeathersJS MCP OAuth Token Fetches] - #168
Conversation
Resolves an N+1 query problem when injecting OAuth tokens into lists of MCP servers by utilizing `getTokensForServers()` in `UserMCPOAuthTokenRepository`. Instead of repeatedly querying for each server's token in `apps/agor-daemon/src/register-hooks.ts`, we now extract the relevant IDs and perform one batched fetch via `inArray`.
|
👋 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: Implemented a batched token retrieval method
getTokensForServersin theUserMCPOAuthTokenRepositoryand refactored theinjectPerUserOAuthTokenshook to pre-fetch all needed tokens using Drizzle'sinArrayprior to mapping.🎯 Why: Previously, when fetching a list of MCP servers (like in a paginated
findendpoint), theinjectTokenmap function would execute an individual database lookup for each MCP server to inject its corresponding OAuth token. This caused an O(N) database query explosion (N+1 query issue).📊 Impact: Severely reduces database round-trips from O(N) to O(1) for lists of MCP servers, lowering query latency, decreasing API response times, and reducing load on the database connection pool.
🔬 Measurement: Review database query logs or use performance monitoring when hitting the
mcp-serversfindendpoint. The number ofSELECTqueries foruser_mcp_oauth_tokenswill remain at exactly one query, regardless of how many MCP servers are returned in the response.PR created automatically by Jules for task 1360143747327675935 started by @Donach