Repository navigation
feat(search): cap per-endpoint fetch at min(page_size, max(limit, floor)) - #83
Merged
Merged
Conversation
…or)) Each search branch now fetches at most min(page_size, max(req.limit, SEARCH_BRANCH_FLOOR)) rows (floor 25), not the full page_size (100 default). The merge truncates to req.limit anyway, so a --limit 25 search previously deserialized ~20 endpoints x 100 rows (2000 rows) to return 25; it now fetches ~20 x 25 (500). The merge/sort/dedupe/truncate behavior is unchanged — each branch just contributes a narrower top-K. A floor of 25 keeps each branch wide enough to rank across endpoints: nbox's score_match is coarser (4 levels: exact/prefix/contains/other) than NetBox's own q relevance, so a cap below the floor could miss a high-scoring row the server ranked lower in the branch. 25 matches the CLI/MCP default --limit. Implementation: a new list_limited method on NetBoxClient (like list but caps the limit param at min(page_size, max)), threaded through all 20 search_* branches. The version-gated branches (vm_types, rack_groups) use it too. Regression tests (3, wiremock): pin the per-endpoint limit= query param so the cap can't drift back to page_size. Mutation-verified: reverting list_limited -> list on the devices branch makes the cap test fail (nbox sends limit=100 instead of 25, the constrained mock isn't hit). Verified: gate green (1110 all-features / 1015 no-default, clippy -D warnings, fmt); live search against 4.6.2 returns correct results for both --limit 5 (floored to 25/branch) and --limit 25 (capped at 25/branch). Existing 1107 tests unchanged (no mock constrains limit on the search paths).
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.
What
Each search branch now fetches at most
min(page_size, max(req.limit, SEARCH_BRANCH_FLOOR))rows (floor 25), not the fullpage_size(100 by default).Why
The merge truncates to
req.limitanyway, so a--limit 25search previously deserialized ~20 endpoints × 100 rows (2000 rows) to return 25. It now fetches ~20 × 25 (500) — a 4× reduction in deserialized rows on the most common search path.The merge/sort/dedupe/truncate behavior is unchanged — each branch just contributes a narrower top-K to the same merge.
The floor
A floor of 25 (not
req.limitdirectly) keeps each branch wide enough to rank across endpoints. nbox'sscore_matchis coarser (4 levels: exact 100 / prefix 50 / contains 25 / other-field 10) than NetBox's ownqrelevance, so a cap below the floor could miss a high-scoring row the server ranked lower in the branch. 25 matches the CLI/MCP default--limitand is wide enough that the top result set is stable in practice.req.limitlimit=sentImplementation
NetBoxClient::list_limited(client.rs) — likelistbut caps thelimitparam atmin(page_size, max).search_restcomputesbranch_limit = self.page_size().min(req.limit.max(SEARCH_BRANCH_FLOOR))once, threads it through all 20search_*branches viatokio::join!.search_*function gains alimit: usizeparam and callsself.list_limited(..., limit)instead ofself.list(...).vm_types,rack_groups) uselist_limitedtoo — the 404-swallow is orthogonal to the cap.Regression tests (3, wiremock)
Pin the per-endpoint
limit=query param so the cap can't drift back topage_size:req.limitlimit=sentsearch_caps_per_endpoint_at_req_limitsearch_floors_per_endpoint_limit_at_25search_caps_per_endpoint_at_page_size_for_large_limitMutation-verified: reverting
list_limited→liston the devices branch makes the cap test fail (nbox sendslimit=100instead of25, the.expect(1)mock withquery_param("limit", "25")isn't hit).Verification
fmt --check,clippy --all-targets --all-features -- -D warnings,test --all-features(1110 pass, +3),test --no-default-features(1015 pass, +3) — all green.--limit 5(floored to 25/branch) and--limit 25(capped at 25/branch).limiton the search paths, so the cap is behaviorally invisible to the suite.Docs
CHANGELOG.md[Unreleased]→### Changedentry.ROADMAP.md"Search per-endpoint row cap" item: ☐ → ☑, reworded as done.Files
src/netbox/client.rs—list_limitedmethod (+24).src/netbox/search.rs—SEARCH_BRANCH_FLOORconst,branch_limitinsearch_rest,limitparam on all 20search_*branches (+78 net).tests/search_tests.rs—mount_empty_all_excepthelper + 3 regression tests (+128).CHANGELOG.md,ROADMAP.md— doc updates.This is the "highest backend win" from the ROADMAP performance backlog — it helps every search path, not just an edge case.