Commit 923b742
refactor(plan): extract caching state out of Visitor into cachingPlannerState
ysmolski flagged that the caching feature added ~900 LOC of two new
responsibilities on top of the planner visitor: a parallel ProvidesData
tree for caching, and per-fetch caching configuration. Visitor was
already 1600+ LOC before; this PR added another 900+ on top.
Extracts those two responsibilities into a sub-struct on Visitor:
type Visitor struct {
...
caching *cachingPlannerState
}
Sub-struct (Option B) chosen over a sibling visitor (Option A) because
the highest-risk part of this code is walker callback ordering. A
sibling visitor adds ordering risk with AllowVisitor, datasource
planner visitors, DefferOnEnterField, and the cost visitor. A sub-struct
preserves callback ordering exactly, with only Visitor registered on
the walker.
Moved to caching_planner_state.go (936 LOC):
- Fields: entityAnalyticsCache, requestScopedVisibleResponseKeys,
requestScopedFetchAliases, plannerObjects, plannerCurrentFields,
plannerResponsePaths, plannerEntityBoundaryPaths.
- Methods: 27 caching-specific methods including configureFetchCaching,
trackFieldForPlanner, popFieldsForPlanner,
configureSubscriptionEntityCachePopulation, entityCacheAnalytics,
polymorphicEntityCacheAnalytics, configureMutationEntityImpact, etc.
- Helper: extractKeyFields.
Preserved on Visitor (load-bearing):
- fieldPlanners — cost visitor captures by pointer.
- plannerFields — fetch deps/reasons read it.
- fieldEnclosingTypeNames — caching state reads through parent.
- Public RequestScopedFetchAlias — kept for external API stability,
delegates to v.caching.fetchAlias.
Net diff: visitor.go shrunk from 2646 to 1766 LOC (-880, -33%).
New caching_planner_state.go: 936 LOC.
Three test files updated for moved helpers (call-site rewrites only,
no logic change):
- visitor_path_normalization_test.go
- request_scoped_provides_data_test.go
- visitor_subscription_entity_population_test.go
Also adds a "Code Comment Conventions" section to CLAUDE.md banning
PR/issue/reviewer references in code comments. Two such references
that crept in during this refactor have been removed from
caching_planner_state.go and visitor_path_normalization_test.go.
Tests: full plan, resolve, execution suites green.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent dd589f8 commit 923b742
7 files changed
Lines changed: 1002 additions & 920 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
170 | 170 | | |
171 | 171 | | |
172 | 172 | | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
173 | 197 | | |
174 | 198 | | |
175 | 199 | | |
| |||
0 commit comments