⚡ [performance] Optimize task and step fetching to eliminate N+1 queries#614
⚡ [performance] Optimize task and step fetching to eliminate N+1 queries#614safal207 wants to merge 1 commit into
Conversation
Refactored TaskManager.get_status to use a LEFT JOIN, reducing queries from 2 to 1. Enhanced TaskManager.list_tasks with an include_steps parameter that uses batch fetching (IN clause), reducing queries from 1+N to 2 for task lists. Measured ~5x speedup for 50 tasks in benchmark. Co-authored-by: safal207 <55020240+safal207@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:
TaskManager.get_statusto use aLEFT JOINbetweentasksandstepstables, reducing the number of queries from 2 to 1 for a single task lookup.include_stepsparameter toTaskManager.list_tasks. When enabled, it fetches all steps for all tasks in a single additional query using aWHERE task_id IN (...)clause, rather than requiring N additional queries if steps were fetched per task.🎯 Why:
Fetching task steps inside a loop (or in multiple separate calls) created an N+1 query pattern, which leads to significant database overhead as the number of tasks grows. These optimizations ensure constant-time query complexity relative to the number of tasks for these common operations.
📊 Measured Improvement:
Correctness was verified by comparing the output of the N+1 pattern against the optimized batch pattern, ensuring identical data structures.
PR created automatically by Jules for task 17682937582860378622 started by @safal207