feat(api): estimate large v3 list counts instead of capping at 10k#1508
Open
andrewklau wants to merge 1 commit into
Open
feat(api): estimate large v3 list counts instead of capping at 10k#1508andrewklau wants to merge 1 commit into
andrewklau wants to merge 1 commit into
Conversation
999c641 to
a39eb19
Compare
The v3 multichain, staking, account-staking and nft-token count endpoints only summed an exact COUNT capped at maxQueryCount, so any large result set rendered as "10,000+" even when the true total is in the millions. Add a shared `countFromEstimate` helper in libs/response.ts (sibling to countFromCagg) that takes a cheap query-planner estimate via count_cost_estimate() and, when the query is both expensive and large (cost > maxQueryCost and rows > maxQueryRows), returns the rounded estimate as an approximate count; otherwise it falls back to the existing exact capped count. Each endpoint now calls the helper instead of repeating the estimate plumbing inline. Adds a <name>Estimate.sql per endpoint (bare filtered SELECT, no LIMIT and no rolling-window upper bound) so EXPLAIN's top-node row estimate reflects the matching-row count. count_cost_estimate already exists in each target database (indexer-signature/-staking/-events), so no migration is needed.
a39eb19 to
50fbe7a
Compare
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.
No description provided.