Skip to content

feat(search): cap per-endpoint fetch at min(page_size, max(limit, floor)) - #83

Merged
lance0 merged 1 commit into
masterfrom
feat/search-per-endpoint-cap
Jun 25, 2026
Merged

lance0 merged 1 commit into
masterfrom
feat/search-per-endpoint-cap

Conversation

@lance0

@lance0 lance0 commented Jun 25, 2026

Copy link
Copy Markdown
Owner

What

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 by default).

Why

The merge truncates to req.limit anyway, so a --limit 25 search 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.limit directly) keeps each branch wide enough to rank across endpoints. nbox's score_match is coarser (4 levels: exact 100 / prefix 50 / contains 25 / other-field 10) 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 and is wide enough that the top result set is stable in practice.

req.limit per-branch limit= sent vs. before (100)
5 25 (floor) 4× fewer
25 25 (cap) 4× fewer
50 50 (cap) 2× fewer
100+ 100 (page_size) same

Implementation

  • NetBoxClient::list_limited (client.rs) — like list but caps the limit param at min(page_size, max).
  • search_rest computes branch_limit = self.page_size().min(req.limit.max(SEARCH_BRANCH_FLOOR)) once, threads it through all 20 search_* branches via tokio::join!.
  • Each search_* function gains a limit: usize param and calls self.list_limited(..., limit) instead of self.list(...).
  • The version-gated branches (vm_types, rack_groups) use list_limited too — 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 to page_size:

Test req.limit asserts limit= sent catches
search_caps_per_endpoint_at_req_limit 25 25 (not 100) cap regression
search_floors_per_endpoint_limit_at_25 5 25 (floor, not 5) floor removal
search_caps_per_endpoint_at_page_size_for_large_limit 200 100 (page_size, not 200) ceiling regression

Mutation-verified: reverting list_limited → list on the devices branch makes the cap test fail (nbox sends limit=100 instead of 25, the .expect(1) mock with query_param("limit", "25") isn't hit).

Verification

  • Gate: fmt --check, clippy --all-targets --all-features -- -D warnings, test --all-features (1110 pass, +3), test --no-default-features (1015 pass, +3) — all green.
  • Live: search against the 4.6.2 box returns correct results for both --limit 5 (floored to 25/branch) and --limit 25 (capped at 25/branch).
  • No churn: existing 1107 tests unchanged — no mock constrains limit on the search paths, so the cap is behaviorally invisible to the suite.

Docs

  • CHANGELOG.md [Unreleased] → ### Changed entry.
  • ROADMAP.md "Search per-endpoint row cap" item: ☐ → ☑, reworded as done.

Files

  • src/netbox/client.rs — list_limited method (+24).
  • src/netbox/search.rs — SEARCH_BRANCH_FLOOR const, branch_limit in search_rest, limit param on all 20 search_* branches (+78 net).
  • tests/search_tests.rs — mount_empty_all_except helper + 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.

…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).
@lance0
lance0 merged commit b0a7fbb into master Jun 25, 2026
4 checks passed
@lance0
lance0 deleted the feat/search-per-endpoint-cap branch June 25, 2026 00:56
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.

1 participant