perf: Cache project identifier lookups - #24
Closed
matthewelwell wants to merge 1 commit into
Closed
Conversation
GetFeature and GetSegment each resolve their project on every call, purely to populate ProjectUUID, which the API never returns. For a caller working through many features in one project -- the Terraform provider, for instance -- that is one redundant request per entity. Caches the immutable identifiers of a project (UUID and organisation) and the UUID to ID mapping, so each is fetched at most once per client. GetFeature and GetSegment drop from two requests to one after the first entity in a project, and getProjectID is now cached too, which also covers CreateFeature, CreateSegment, UpdateSegment and GetTag. Only immutable fields are cached. GetProject and GetProjectByID stay live, so a caller that reads a project after updating it still sees current values. Also exports GetProjectIDByUUID, so callers that need a project ID before they have one -- creating a feature, for example -- can resolve it without a second round trip of their own. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
matthewelwell
force-pushed
the
perf/cache-project-lookups
branch
from
August 25, 2026 18:00
801dcee to
fd5b450
Compare
Contributor
Author
|
Closing: premature optimisation. If it does become worth doing, the right fix is probably upstream anyway: |
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.
GetFeatureandGetSegmentresolve their project on every call, purely to populateProjectUUID— which the API never returns. For a caller working through many features in one project, that's a redundant request per entity.This caches the immutable identifiers of a project (UUID and organisation ID) and the UUID→ID mapping, so each is fetched at most once per client.
getProjectIDis cached too, soCreateFeature,CreateSegment,UpdateSegmentandGetTagbenefit as well.What is and isn't cached
Only immutable fields: a project's UUID and its organisation.
GetProjectandGetProjectByIDstay uncached, so a caller reading a project after updating it still sees current values. That's the whole reason for the narrowprojectRefstruct rather than caching*Project.Cache lifetime is the client's lifetime, with no invalidation. That's the right trade for a short-lived client (the Terraform provider builds one per plan/apply); a long-lived process would hold these until restart, which is safe precisely because the cached fields can't change.
Also exported
GetProjectIDByUUID, so callers that need a project ID before they have one — creating a feature, say — can resolve it without a round trip of their own.🤖 Generated with Claude Code