Repository navigation
Conversation
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.
Summary
Listing N documents currently performs N separate topic-count queries, in addition to the total-count and page queries. A 100-document page executes 102 SELECTs and fans out database sessions.
Add a grouped topic count for the page's document IDs and call it once from
list_documents. Nonempty pages now execute 3 SELECTs; empty pages execute 2. Preserve zero counts, scope/category filters, ordering, pagination metadata, and the existing single-document count method.Area
Verification
Real SQLite regressions reproduced 22 and 102 SELECTs for 20- and 100-document pages before the fix, plus 5 SELECTs for a filtered 3-document page. After the fix, all 26 targeted tests passed on Python 3.12.13 / macOS.
The full repository checks passed: lint and architecture gates; 2751 unit tests passed (4 skipped); 193 integration tests passed (9 skipped, 7 deselected by the default test configuration); sdist/wheel build and wheel-import smoke test passed.
The local file-size gate uses the target
upstream/mainbecause this fork'sorigin/mainhas no merge base with the target. The invocation below runs the existingcitarget with only that gate's base argument adjusted; no Makefile change is included:make -f <(sed 's@python scripts/check_file_sizes.py$@python scripts/check_file_sizes.py --base upstream/main@' Makefile) ciThe three independent patches were also applied together in a temporary worktree: 60 relevant compatibility tests passed.
Checklist
main..envfiles, dependency folders, or generated output.Notes for Reviewers
The query-budget tests observe actual SQLite statements, including empty pages, zero-topic documents, duplicate/missing IDs, and filtered pagination. No wall-clock latency improvement is claimed. No schema, HTTP contract, or dependency changes are needed.
By submitting this pull request, I agree that my contribution is licensed under
the Apache License 2.0.