⚡ Refactor shapeBrokerPortfolio for batched pricing#40
Conversation
Refactored `shapeBrokerPortfolio` in `src/tools/portfolio.ts` to accept a batched `priceFor` callback instead of a single-ticker one. This allows callers to fetch required prices in a batched manner, which deduplicates identical tickers across different sub-accounts and resolves the underlying architectural N+1 fetch query issue. While the actual vendor APIs (e.g., DNSE) do not natively support comma-separated bulk fetch queries at the moment, this structural update ensures that we at least deduplicate identical positions and perfectly sets up the callback API for when true bulk fetch is implemented or injected from a different provider. Co-authored-by: toreleon <42534763+toreleon@users.noreply.github.com>
|
👋 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: The optimization implemented
shapeBrokerPortfoliosignature insrc/tools/portfolio.tsto accept a batchedpriceForcallback(tickers: string[]) => Promise<Record<string, number | null>>.snap.positionsneeding price fetches to avoid redundant API queries.listPositionsToolto provide a matching bulk callback, and updated tests similarly.🎯 Why: The performance problem it solves
priceForcallback sequentially inPromise.all. This caused a burst of individual fetch requests, which was exacerbated if multiple sub-accounts held positions of the same stock (duplicate fetching). The new structure batches required tickers into a single call, eliminating the N+1 problem at the application layer and allowing for deduplication.📊 Measured Improvement:
Promise.allmapping occurs in the callback implementation (listPositionsTool), meaning this structurally prepares for batch APIs while immediately offering deduplication improvements and lower overhead.PR created automatically by Jules for task 18337204468161048743 started by @toreleon