Missing index on turns.state slows down scheduler queries
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 72/100
Research direction
Start by locating the turns table schema and the project's database migration entry point, then inspect how existing indexes are defined. Add the partial index covering queued and running turns ordered by created_at, and verify the scheduler query uses it without breaking migration or schema checks.
Written by the indexing model from the issue text.
Description
Hey, was poking around the schema and noticed the turns table has indexes on (orgId, storyId, createdAt) and a few unique ones, but nothing on state alone or (state, createdAt).
The scheduler needs to find all queued turns globally:
SELECT * FROM turns WHERE state = 'queued' ORDER BY created_at LIMIT 10;
Without an index on that, it's a full table scan. Not a big deal when you've got a handful of turns, but as the system grows this becomes the bottleneck for turn dispatch.
Easy fix - a partial index that only covers active states:
CREATE INDEX turns_state_created_idx ON turns(state, created_at)
WHERE state IN ('queued', 'running');
Keeps it small and efficient since those are the only states the scheduler actually queries. Thought it was worth flagging before it becomes a problem.
- Dominant language
- TypeScript
- Stars
- 71
- Forks
- 64
- Avg merge
- 15h 38m
- Merged PRs (30d)
- 66
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from theam/facility
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
enhancement
Difficulty 1/5 Under an hour Newbie friendliness 92/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Similar issues
-
calcite-components needs triage refactor
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Esri/calcite-design-system#15203 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 91/100
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
Difficulty 1/5 Under an hour Newbie friendliness 95/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Automattic/studio#4908 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 90/100