Skip to content

Add index on runs.finished_at#4308

Merged
stuartc merged 2 commits intomainfrom
runs_finished_at_index
Jan 14, 2026
Merged

Add index on runs.finished_at#4308
stuartc merged 2 commits intomainfrom
runs_finished_at_index

Conversation

@stuartc
Copy link
Member

@stuartc stuartc commented Jan 13, 2026

Description

This PR adds an index on runs.finished_at to fix database timeouts in the UsageTracking ReportWorker.

We were seeing daily Sentry errors where the worker timed out after 70+ seconds:

Postgrex.Protocol disconnected: client timed out because it queued and checked out the connection for longer than 70000ms

The WorkflowMetricsService queries runs by finished_at date range, but there was no index on that column - causing full table scans.

Validation steps

  1. Index is already deployed and working in production
  2. Stats show 161k index scans over 12 days with 25M tuples read
  3. Timeout errors reduced from daily to 1 in the last two weeks

Additional notes for the reviewer

The migration uses create_if_not_exists and concurrently: true - it's already been applied manually to production.

AI Usage

  • Code generation (copilot but not intellisense)
  • Learning or fact checking
  • Strategy / design
  • Optimisation / refactoring
  • Translation / spellchecking / doc gen
  • Other
  • I have not used AI

You can read more details in our Responsible AI Policy

Pre-submission checklist

  • I have performed a self-review of my code.
  • I have implemented and tested all related authorization policies.
  • I have updated the changelog.
  • I have ticked a box in "AI usage" in this PR

@github-project-automation github-project-automation bot moved this to New Issues in v2 Jan 13, 2026
@stuartc stuartc requested a review from rorymckinley January 13, 2026 11:53
@stuartc stuartc self-assigned this Jan 13, 2026
@codecov
Copy link

codecov bot commented Jan 13, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.30%. Comparing base (9e63d12) to head (b173e8e).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4308      +/-   ##
==========================================
- Coverage   89.33%   89.30%   -0.03%     
==========================================
  Files         425      425              
  Lines       19913    19913              
==========================================
- Hits        17789    17784       -5     
- Misses       2124     2129       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@stuartc stuartc merged commit d074b4e into main Jan 14, 2026
7 of 8 checks passed
@stuartc stuartc deleted the runs_finished_at_index branch January 14, 2026 06:28
@github-project-automation github-project-automation bot moved this from New Issues to Done in v2 Jan 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants

Comments