Repository navigation
perf(api): avoid model hydration for pagination counts - #9953
Draft
GODOSTROYER wants to merge 1 commit into
Draft
GODOSTROYER wants to merge 1 commit into
GODOSTROYER wants to merge 1 commit into
Conversation
Keep supplied count querysets lazy and count projected pages without loading their models. Preserve raw querysets, custom lengths, grouping, and row locks, with unit and PostgreSQL/API regression coverage.
Contributor
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This branch has not been deployed
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.
Description
Offset pagination currently evaluates a supplied
total_count_querysetfor truthiness before calling.count(), constructing every matching model even when only one page is returned. A projection callback can then trigger a second fetch of the raw page when response metadata callslen(cursor_result).This change checks the optional count source against
Noneand uses SQL counting for transformed, sliced, non-locking querysets with the standardCursorResult. It preserves custom length behavior, row locks, grouped-query behavior, and raw-response cache reuse. An explicitly supplied empty count queryset now correctly supplies zero instead of falling back to the page queryset. Callers must continue to supply equivalently scoped count and result querysets.Type of Change
Screenshots and Media (if applicable)
Not applicable.
Test Scenarios
Representative local workload: 1,000 matching work items, page size 20, 4-KiB description payload per representation. Medians from 20 randomized trials after two warmups:
fields=id,nameConstructed work-item models fell from 1,020 to 20 for the public response and from 1,020 to zero for the app projection. SQL statement counts remained 9 and 7 respectively. Responses matched across all variants. Timings cover APIClient request handling plus JSON parsing with
DEBUG=False; SQL, allocation, and query-plan probes were separate. Smaller-workload timing differences vary; these are local observations, not production or universal speedup claims. Hosted checks and maintainer review remain separate.References