Skip to content

Refactor controller: dedup shared pipeline and split RPCs into focused helpers#111

Closed
sbalabanov wants to merge 1 commit into
mainfrom
controller
Closed

Refactor controller: dedup shared pipeline and split RPCs into focused helpers#111
sbalabanov wants to merge 1 commit into
mainfrom
controller

Conversation

@sbalabanov

Copy link
Copy Markdown
Contributor

Summary

The four streaming RPCs in controller/ had grown into ~700-line files that
duplicated the same scaffolding around revision validation, treehash lookup,
cache drains, two-revision graph fetch, name/ID transposition, and
INDIRECT→DIRECT promotion. This PR pulls the shared logic into small,
named helpers and re-expresses each RPC as a top-to-bottom pipeline.

  • rpc_helpers.gorecordRPCResult defer used by every RPC;
    validateRevisionPair shared by both Changed-Targets validators.
  • cache.go — generic cacheReader[T] interface plus readTreehash,
    readTreehashPair, and loadCachedResponses[T] unify cache scaffolding
    across the two response types.
  • graphfetch.gofetchTwoGraphs concurrently retrieves both revisions
    with sibling cancellation on the first failure.
  • mappers.goidMappers bundles the five canonical name→ID mappers
    and exposes transpose/chunkMetadata.
  • classify.gopromoteToDirectIfNeeded centralizes the
    INDIRECT→DIRECT promotion rules.
  • getchangedtargets.go and getchangedtargetsandedges.go shrink by ~400
    lines combined and now read as a sequence of named pipeline steps.

All test-referenced symbols are preserved (validateGetChangedTargetsRequest,
validateGetChangedTargetsAndEdgesRequest, computeDistances,
sendWithDistanceFilter, sendWithDistanceFilterForEdges, buildEdgeSet,
transposeOptimizedTarget) — no test changes were needed.

Test plan

  • go build ./...
  • go vet ./controller/...
  • gofmt -l ./controller/ clean
  • go test ./controller/...
  • go test -race ./controller/...

🤖 Generated with Claude Code

…d helpers

The four controller RPCs duplicated large amounts of pipeline scaffolding —
revision validation, treehash lookup, cached-response drains, concurrent
two-graph fetch, name/ID transposition, and INDIRECT->DIRECT promotion all
lived twice in side-by-side ~700-line files. Pull the shared logic into
small, well-named helpers and re-express each RPC as a top-to-bottom pipeline.

- rpc_helpers.go: recordRPCResult defer used by every RPC; validateRevisionPair
  shared by GetChangedTargets and GetChangedTargetsAndEdges validators.
- cache.go: cacheReader[T] generic interface plus readTreehash/
  readTreehashPair/loadCachedResponses unify the cache scaffolding.
- graphfetch.go: fetchTwoGraphs concurrently fetches both revisions with
  sibling cancellation on the first failure.
- mappers.go: idMappers bundles the five canonical name->ID mappers and
  exposes transpose/chunkMetadata.
- classify.go: promoteToDirectIfNeeded centralizes the INDIRECT->DIRECT
  promotion rules.

Each RPC body shrinks dramatically — getchangedtargets.go and
getchangedtargetsandedges.go drop ~400 lines combined while preserving
every test-referenced symbol (validateGetChangedTargetsRequest,
validateGetChangedTargetsAndEdgesRequest, computeDistances,
sendWithDistanceFilter, sendWithDistanceFilterForEdges, buildEdgeSet,
transposeOptimizedTarget). Existing tests pass unchanged.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@sbalabanov sbalabanov closed this Jun 12, 2026
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.

3 participants