Fix: Attempt at improving worker actions query#3774
Open
mrkaye97 wants to merge 14 commits into
Open
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
04abf76 to
0692172
Compare
mrkaye97
commented
Apr 28, 2026
| ; | ||
|
|
||
| -- name: GetWorkerActionsByWorkerActionHash :many | ||
| SELECT DISTINCT ON (w."actionHash") |
Contributor
Author
There was a problem hiding this comment.
goal here is we'll just move to this completely in a little bit, once all the workers have hashes
Contributor
There was a problem hiding this comment.
Pull request overview
This PR aims to reduce slow traces in the worker actions lookup path by adding an actionHash to workers and using it to de-duplicate action lookups across identical worker replicas, falling back to worker-id lookups for backward compatibility.
Changes:
- Add
Worker.actionHash(BYTEA) plus a(tenantId, actionHash)index (schema + migrations). - Introduce a new repository method to fetch worker actions using action-hash de-duplication with worker-id fallback.
- Update worker list/get handlers to call the new repository API and pass full worker rows.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| sql/schema/v0.sql | Adds actionHash column and a (tenantId, actionHash) index to the baseline schema. |
| cmd/hatchet-migrate/migrate/migrations/20260428204451_v1_0_103.sql | Adds the actionHash column for existing installations. |
| cmd/hatchet-migrate/migrate/migrations/20260428213451_v1_0_104.sql | Adds the (tenantId, actionHash) index concurrently for existing installations. |
| pkg/repository/worker.go | Implements action-hash-based action lookup and hashes actions on worker creation. |
| pkg/repository/sqlcv1/workers.sql | Updates worker-actions queries and adds a new query by actionHash. |
| pkg/repository/sqlcv1/workers.sql.go | Regenerated sqlc output for updated queries/columns. |
| pkg/repository/sqlcv1/models.go | Adds ActionHash field to the Worker model. |
| api/v1/server/handlers/workers/list.go | Uses the new worker-actions repository method and passes worker rows. |
| api/v1/server/handlers/workers/get.go | Uses the new worker-actions repository method for single-worker fetch. |
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.
Description
Lots of slow traces, which I think are happening because we're pulling a ton of rows down out of the db. I figured we could hash the action names and store them with the worker, and then try to only look up actions for each hash once, and then map them back to the relevant worker that way, which should cut down the number of rows we need to pull out of the db by a factor of the number of replicas of a worker any given tenant has
Unfortunately we can't make the action hash non-null and backfill so we need to also have a lookup by worker id for backwards compat for now
Type of change