fix(bling): paginate list_orders_with_items by summary page (fixes #219) - #220
Merged
Conversation
Previously the handler re-fetched every summary page in the date range on every call and sliced client-side, so paging a large range cost O(pages × batches) summary requests, sharing the ~3 req/sec budget with the per-order detail fetches. Fetch a single summary page per call (keyed by `page`), filter canceled within it, and fetch details only for that page — one summary request per call, O(pages) overall. Also names the canceled-status magic number (CANCELED_STATUS). Interface change: batchPage/batchSize → page; the response now returns page/pageSize/fetchedOnPage/nextPage (up to 100 orders per call). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Review follow-up on the pagination change: - Add optional pageSize (default 25, max 100) used directly as the API `limite`, so a single cursor bounds both the summary request and the detailed set — a dense page no longer risks the MCP client timeout (default ~9s/call). Integer-coerced so a fractional value can't silently stop pagination early. - Rewrite the guard test to key on `page` (asserts pagina=N + bounded detail calls); it now fails against the pre-fix code instead of passing vacuously. - Throw when dataInicial/dataFinal are missing. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Summary
Fixes #219.
list_orders_with_items(added in #179) re-fetched the entire order-summary list for the date range on every call and sliced client-side, so paging a large range costO(pages × batches)summary requests — and those redundant requests shared the ~3 req/sec budget with the per-order detail fetches (real waste + timeout/rate risk on long ranges).This fetches a single summary page per call instead: one
/pedidos/vendaspage, filter canceled within it, fetch details only for that page. Paging a range is nowO(pages).Changes
page(no full-rangewhileloop, no client-sideslice).pageSize(optional, default 25, max 100) is passed straight through as the APIlimite, so a single cursor bounds both the one summary request and the detailed set. This keeps per-call latency in check — the detail phase runs 2-at-a-time with a 700ms gap, so ~25 orders ≈ 9s vs ~35s for a full 100. A caller hitting an MCP timeout on dense pages can lowerpageSize. (This preserves the reasonbatchSizeexisted in feat(bling): add 6 new tools for order details, stores, statuses, products and warehouses #179 — bounded per-call cost — without the full-range re-fetch.)CANCELED_STATUS(2).dataInicial/dataFinalare missing (they arerequired, but the handler no longer silently lists all dates).batchPage/batchSize→page+pageSize.page,pageSize,fetchedOnPage,hasMore,nextPage(wasbatchPage/batchSize/totalOrders/fetchedRange/nextBatchPage).totalOrdersis dropped — computing it required the full-range fetch this PR removes.Behavior notes
hasMoreissummaries.length === pageSize(full page ⇒ maybe more; short page ⇒ last).pageSizeis integer-coerced so a fractional value can't makehasMorefalse and stop paging early.excludeCanceled=true, an intermediate full page that happens to be all-canceled returnsorders: []withhasMore=true— correct; the caller advances onhasMore/nextPage, not onorders.length.Test
Added a unit test asserting exactly one summary request per call, keyed by
page(pagina=3when called withpage: 3) plus a bounded detail-request count. Verified it fails against the pre-fix code (which always started its summary walk atpagina=1), so it's a genuine regression guard — not vacuous. Full suite: 148 passed / 32 skipped,tsc --noEmitclean, catalog audit HIGH: 0.Review
Adversarially reviewed (two rounds): the review caught that the first version of the guard test was vacuous and that a full-100-order page reintroduced the MCP-timeout risk — both addressed here.