[codex] Improve stats job allocation reads - #68
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR reduces database load during daily stats generation by replacing per-job allocation lookups with a single bulk read that deterministically selects the latest stored allocation per job, and only falls back to the Deeploy API when a job ID is absent from storage.
Changes:
- Added
GetAllocationsByJobIDsForJobDetailsbulk lookup to fetch the latest allocation per job ID (PostgresDISTINCT ONwith deterministic ordering). - Updated
DailyGetStatsto use the bulk lookup instead of one DB query per unique job ID. - Added storage-level tests validating latest-allocation selection and empty-input behavior.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
storage/allocationStorer.go |
Adds bulk allocation lookup by job IDs and refactors single-job lookup to use it. |
storage/allocationStorer_test.go |
Introduces tests for bulk lookup selection logic and empty input handling. |
service/statsService.go |
Switches daily stats job-detail enrichment to the new bulk allocation lookup. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+12
to
+15
| func TestGetAllocationsByJobIDsForJobDetails(t *testing.T) { | ||
| db, err := GetDB() | ||
| require.NoError(t, err) | ||
|
|
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.
Summary
DailyGetStatsto avoid one DB read per unique jobValidation
gofmt -w service/statsService.go storage/allocationStorer.go storage/allocationStorer_test.gogit diff --checkgo build ./...go test ./service -run '^$' -count=1\n\n## Test blockers\n-go test ./storage -run 'TestGetAllocationsByJobIDsForJobDetails' -count=1is blocked before test execution by existingstorage/init_test.gozero-value DB config (lookup port=0: no such host).\n-go test ./... -run '^$' -count=1is blocked by the same storage initializer and by existing templates test setup expectingemail.confirm.htmlrelative to the test working directory.\n