Skip to content

[codex] Improve stats job allocation reads - #68

Merged
aledefra merged 1 commit into
developfrom
codex/improve-db-reads
Jun 9, 2026
Merged

[codex] Improve stats job allocation reads#68
aledefra merged 1 commit into
developfrom
codex/improve-db-reads

Conversation

@aledefra

@aledefra aledefra commented Jun 7, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • add a bulk allocation lookup for job-detail enrichment by job IDs
  • use the bulk lookup in DailyGetStats to avoid one DB read per unique job
  • fall back to Deeploy API only for job IDs absent from storage
  • select the latest stored allocation per job deterministically by block, allocation timestamp, and id

Validation

  • gofmt -w service/statsService.go storage/allocationStorer.go storage/allocationStorer_test.go
  • git diff --check
  • go build ./...
  • go test ./service -run '^$' -count=1\n\n## Test blockers\n- go test ./storage -run 'TestGetAllocationsByJobIDsForJobDetails' -count=1 is blocked before test execution by existing storage/init_test.go zero-value DB config (lookup port=0: no such host).\n- go test ./... -run '^$' -count=1 is blocked by the same storage initializer and by existing templates test setup expecting email.confirm.html relative to the test working directory.\n

@aledefra
aledefra marked this pull request as ready for review June 9, 2026 10:44
Copilot AI review requested due to automatic review settings June 9, 2026 10:44

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 GetAllocationsByJobIDsForJobDetails bulk lookup to fetch the latest allocation per job ID (Postgres DISTINCT ON with deterministic ordering).
  • Updated DailyGetStats to 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)

@aledefra
aledefra merged commit 87a6a76 into develop Jun 9, 2026
1 check passed
@aledefra
aledefra deleted the codex/improve-db-reads branch June 9, 2026 10:49
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.

2 participants