perf(node): stop requesting the peer count of many relationships - #1294
Open
fatih-acar wants to merge 1 commit into
Open
perf(node): stop requesting the peer count of many relationships#1294fatih-acar wants to merge 1 commit into
fatih-acar wants to merge 1 commit into
Conversation
The query the SDK renders for a cardinality-many relationship asked for `count` next to `edges`, but nothing ever read it back: the manager is built from the edges alone, and only the top-level pagination count is consumed. Infrahub resolves that nested count with one extra database query per returned node and per relationship, awaited before the peers are loaded, which also splits the batched peer read into several partial ones. Measured on 25 nodes carrying one Attribute-kind relationship (the shape every `all()` query renders by default): 62 database queries with the count, 9 without. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. @@ Coverage Diff @@
## stable #1294 +/- ##
==========================================
+ Coverage 84.16% 84.23% +0.07%
==========================================
Files 147 147
Lines 13045 13045
Branches 1930 1930
==========================================
+ Hits 10979 10989 +10
+ Misses 1503 1493 -10
Partials 563 563
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 2 files with indirect coverage changes 🚀 New features to boost your workflow:
|
gmazoyer
approved these changes
Aug 27, 2026
ajtmccarty
approved these changes
Aug 27, 2026
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.
Why
The query the SDK renders for every cardinality-many relationship asks for
countnext toedges, and nothing reads it back: the relationship manager is built fromedgesalone, and the only counts the SDK consumes are the top-level pagination count and the hand-writtenmember_of_groups { count }ofinfrahubctl info.On the server that nested
countis not free. Infrahub resolves it with a dedicatedrelationship_get_peer_countquery per returned node and per relationship, awaited before the peers are loaded — which also splits the batched peer read (relationship_get_peer) into several partial queries.Attribute-kind relationships such astagsare rendered by everyall()/filters()/get()call by default, so this cost is paid on nearly every SDK read.Goal: stop asking for a value that is never used.
Non-goals: a server-side mitigation for SDKs already deployed (they keep sending
count) — that is an Infrahub change, tracked separately.What changed
all(),filters(),get(), relationshipfetch()and the hierarchicalchildren/ancestors/descendantsblocks no longer includecountin cardinality-many relationship blocks.countand themember_of_groups { count }ofinfrahubctl infoare unchanged.RelationshipManagerBase._generate_query_data, shared by the async and sync managers. Response processing is untouched —RelationshipManagernever looked atcount.tests/unit/sdk/test_node.pythat pinned the nested field are updated, and the two_generate_query_datatests now assert the field is absent.How to test
Measured against Infrahub with a component test that runs the exact query the SDK renders through a query-counting database — 25
TestPersonnodes carrying 2 peers per relationship,tagsbeing anAttribute-kind relationship (rendered by default) andcarsaGeneric-kind one (rendered viainclude):count(total / peer reads / count reads)all("TestPerson")all("TestPerson", include=["cars"])all("TestPerson", prefetch_relationships=True)Impact & rollout
execute_graphqlare unaffected.Checklist
🤖 Generated with Claude Code
Summary by cubic
Stops requesting the
countfield on cardinality-many relationship blocks in SDK-generated queries, since nothing ever reads it—but Infrahub resolved it with one extra database query per returned node and per relationship, and it also prevented peer reads from being batched into a single query. Removing it cuts database queries substantially (for example,all("TestPerson")drops from 62 to 9 queries on a 25-node test) and restores peer-read batching. The top-level paginationcountand themember_of_groups { count }used byinfrahubctl infoare unchanged.Written for commit 68ce4cc. Summary will update on new commits.