Skip to content

perf(dora): optimize change lead time calculation using batch queries#8714

Draft
AnkeshThakur wants to merge 1 commit intoapache:mainfrom
AnkeshThakur:feat-optimize-change-lead-time-batch-queries
Draft

perf(dora): optimize change lead time calculation using batch queries#8714
AnkeshThakur wants to merge 1 commit intoapache:mainfrom
AnkeshThakur:feat-optimize-change-lead-time-batch-queries

Conversation

@AnkeshThakur
Copy link

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

  • Implemented batchFetchFirstCommits() - fetches all first commits in a single query
  • Implemented batchFetchFirstReviews() - fetches all first reviews in a single query
  • Implemented batchFetchDeployments() - fetches all deployments in a single query
  • Modified CalculateChangeLeadTime() to call batch functions upfront and use O(1) map lookups

Bug Fix

  • Fixed NULL author_id handling in review queries to properly process PRs with empty author_id field

Performance Impact

Before optimization:

  • 3 database queries per PR
  • For 10,000 PRs: 30,001 queries

After optimization:

  • 3 batch queries total regardless of PR count
  • For 10,000 PRs: 3 queries (99.99% reduction)

Testing

  • ✅ All existing unit tests pass
  • ✅ All E2E tests pass including edge cases with NULL author_id
  • ✅ Batch fetch operations complete in ~5-6ms for test dataset
  • ✅ Data integrity verified - results match previous implementation

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.

@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. component/plugins This issue or PR relates to plugins improvement priority/high This issue is very important labels Feb 14, 2026
@AnkeshThakur AnkeshThakur marked this pull request as draft February 14, 2026 10:03
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>
@AnkeshThakur AnkeshThakur force-pushed the feat-optimize-change-lead-time-batch-queries branch from 59ed07e to d536475 Compare February 14, 2026 10:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component/plugins This issue or PR relates to plugins improvement priority/high This issue is very important size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant