Skip to content

Conversation

@wlggraham
Copy link
Contributor

@wlggraham wlggraham commented Jan 22, 2026

PR Details

Description

With the introduction of job cancellation in the previous PR, we noticed some performance issues with the query that was selecting jobs to be cleaned up by the janitor. To mitigate these issues, this PR does the following:

  1. Updates the query to no longer use 'OR' logic, which was causing a large scan on the jobs table
  2. Adds an index on (job_status_id, system_job_id) - several of our queries are using status_id
  3. Moves canceled SYNC jobs directly to 'CANCELED' status instead of 'CANCELLING' to prevent the need for janitor cleanup.

The ANALYZE on the new query reported a significant drop in execution time (multiple seconds to a few hundred milliseconds).

Types of changes

  • Docs change / refactoring / dependency upgrade
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation and I have updated the documentation accordingly.
  • I have added tests to cover my changes.

@wlggraham wlggraham merged commit 9362e40 into main Jan 22, 2026
6 checks passed
@wlggraham wlggraham deleted the optimize_cancel_query branch January 22, 2026 20:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants