perf(dora): optimize change lead time calculation using batch queries#8714
Draft
AnkeshThakur wants to merge 1 commit intoapache:mainfrom
Draft
perf(dora): optimize change lead time calculation using batch queries#8714AnkeshThakur wants to merge 1 commit intoapache:mainfrom
AnkeshThakur wants to merge 1 commit intoapache:mainfrom
Conversation
Eliminates N+1 query problem by implementing batch fetching for: - First commits per PR (batchFetchFirstCommits) - First reviews per PR (batchFetchFirstReviews) - Deployments per project (batchFetchDeployments) Performance improvement: - Before: 3 queries per PR (30,001 queries for 10K PRs) - After: 3 batch queries total (99.99% reduction) Also fixes NULL author_id handling in review queries to properly handle PRs with empty author_id field. Tested with E2E tests confirming correctness and performance gains. Signed-off-by: Ankesh <athakur@g2.com>
59ed07e to
d536475
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR optimizes the change lead time calculation in the DORA plugin by eliminating the N+1 query problem through batch fetching.
Changes
Performance Optimization
batchFetchFirstCommits()- fetches all first commits in a single querybatchFetchFirstReviews()- fetches all first reviews in a single querybatchFetchDeployments()- fetches all deployments in a single queryCalculateChangeLeadTime()to call batch functions upfront and use O(1) map lookupsBug Fix
author_idhandling in review queries to properly process PRs with empty author_id fieldPerformance Impact
Before optimization:
After optimization:
Testing
Related Issue
This addresses performance issues with change lead time calculation for repositories with large numbers of pull requests, where the previous implementation caused significant database load and slow calculation times.