Skip to content

perf(db): batch-fetch content hashes in merge and rebase loops#469

Merged
dlorenc merged 1 commit into
mainfrom
work/jolly-owl
May 9, 2026
Merged

perf(db): batch-fetch content hashes in merge and rebase loops#469
dlorenc merged 1 commit into
mainfrom
work/jolly-owl

Conversation

@dlorenc

@dlorenc dlorenc commented May 9, 2026

Copy link
Copy Markdown
Owner

Summary

  • Added batchFetchVersionContentHashes(ctx, tx, versionIDs []string) (map[string]string, error) that issues a single SELECT version_id::text, content_hash FROM documents WHERE version_id = ANY($1) instead of one query per file
  • Replaced the N-query loop in Merge (~line 718) with a pre-fetch + map lookup
  • Replaced the N-query loop in Rebase (~line 874) with a pre-fetch of all version IDs across all rebase groups before the outer loop, then map lookups inside

The existing fetchVersionContentHash is kept (still used nowhere after this change, but left for potential future use — could be cleaned up separately).

Test plan

  • go build ./... — clean
  • go vet ./... — clean
  • go test ./... -count=1 — all packages pass; TestDockerSmoke in internal/server fails due to a pre-existing GCP registry auth issue unrelated to this change (requires gcloud auth login)

Notes

  • Opportunities not pursued: fetchVersionContentHash is now unused and could be deleted; worth a follow-up cleanup PR.
  • The pq.Array helper (already imported via github.com/lib/pq) handles the uuid[] conversion for ANY($1) correctly.

🤖 Generated with Claude Code

Replace per-file fetchVersionContentHash() calls (N queries for N files)
with a single batchFetchVersionContentHashes() call using ANY($1) in both
the merge commit hash loop (~line 718) and the rebase replay loop (~line
874). Introduces batchFetchVersionContentHashes(ctx, tx, versionIDs) that
does SELECT version_id, content_hash FROM documents WHERE version_id =
ANY($1) and returns a map for O(1) lookups.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <[email protected]>
@dlorenc dlorenc merged commit c42cab1 into main May 9, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant