⚡ Bolt: Use shared httpx.AsyncClient for concurrent uploads#54
⚡ Bolt: Use shared httpx.AsyncClient for concurrent uploads#54kourdroid wants to merge 1 commit into
Conversation
Refactored `SupabaseStorage.upload` and `download` methods to accept an optional `httpx.AsyncClient` parameter. Updated the `ingest` route to instantiate an `httpx.AsyncClient` inside an `async with` context block and pass it to the concurrent file upload calls. This eliminates repeated TCP/TLS handshake overhead while preventing race conditions by not mutating instance state. Mocks in tests were updated accordingly. Co-authored-by: kourdroid <36898160+kourdroid@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:
Updated
SupabaseStorageto accept an optionalhttpx.AsyncClientin itsuploadanddownloadmethods. Insrc/api/routes.py, anhttpx.AsyncClientis instantiated and shared across all concurrent file uploads inasyncio.gather.🎯 Why:
Previously, a new
httpx.AsyncClientwas instantiated for every split file upload during ingestion. This incurred expensive TCP and TLS handshakes for each HTTP request, creating a performance bottleneck when handling documents with many splits. Attempting to use a request-scoped class context manager (__aenter__) could cause race conditions, so passing the client explicitly is safer.📊 Impact:
Significantly reduces I/O latency and CPU overhead during PDF split processing. For multi-split PDFs, the total ingest time is expected to drop by eliminating N round-trip handshakes to Supabase storage.
🔬 Measurement:
Profile the latency of the
/ingestroute when uploading a multi-page PDF (e.g., > 10 pages). Observe the reduction in connection establishment overhead in logging or tracing. The behavior has been verified with existing unit tests.PR created automatically by Jules for task 12198355291564608865 started by @kourdroid