Repository navigation
perf(api): batch indexing status segment counts - #42191
Merged
fatelei merged 1 commit intoSep 11, 2026
Merged
Conversation
Contributor
Pyrefly Diffbase → PR--- /tmp/pyrefly_base.txt 2026-09-11 07:17:05.996001224 +0000
+++ /tmp/pyrefly_pr.txt 2026-09-11 07:16:57.851813687 +0000
@@ -3421,15 +3421,15 @@
ERROR Argument `scoped_session[flask_sqlalchemy.session.Session]` is not assignable to parameter `session` with type `sqlalchemy.orm.session.Session` in function `_add_binding` [bad-argument-type]
--> tests/unit_tests/controllers/console/datasets/test_data_source.py:85:28
ERROR Missing argument `name` in function `controllers.console.datasets.datasets.DatasetCreatePayload.__init__` [missing-argument]
- --> tests/unit_tests/controllers/console/datasets/test_datasets.py:581:49
+ --> tests/unit_tests/controllers/console/datasets/test_datasets.py:591:49
ERROR Object of class `NoneType` has no attribute `token` [missing-attribute]
- --> tests/unit_tests/controllers/console/datasets/test_datasets.py:1448:16
+ --> tests/unit_tests/controllers/console/datasets/test_datasets.py:1517:16
ERROR Argument `Literal['custom']` is not assignable to parameter `mode` with type `ProcessRuleMode | SQLCoreOperations[ProcessRuleMode]` in function `models.dataset.DatasetProcessRule.__init__` [bad-argument-type]
- --> tests/unit_tests/controllers/console/datasets/test_datasets_document.py:245:18
+ --> tests/unit_tests/controllers/console/datasets/test_datasets_document.py:246:18
ERROR Argument `Literal['custom']` is not assignable to parameter `mode` with type `ProcessRuleMode | SQLCoreOperations[ProcessRuleMode]` in function `models.dataset.DatasetProcessRule.__init__` [bad-argument-type]
- --> tests/unit_tests/controllers/console/datasets/test_datasets_document.py:280:67
+ --> tests/unit_tests/controllers/console/datasets/test_datasets_document.py:281:67
ERROR Argument `Literal['custom']` is not assignable to parameter `mode` with type `ProcessRuleMode | SQLCoreOperations[ProcessRuleMode]` in function `models.dataset.DatasetProcessRule.__init__` [bad-argument-type]
- --> tests/unit_tests/controllers/console/datasets/test_datasets_document.py:1505:67
+ --> tests/unit_tests/controllers/console/datasets/test_datasets_document.py:1543:67
ERROR Argument `Literal['opendal']` is not assignable to parameter `storage_type` with type `StorageType` in function `models.model.UploadFile.__init__` [bad-argument-type]
--> tests/unit_tests/controllers/console/datasets/test_datasets_segments.py:137:22
ERROR Argument `Literal['account']` is not assignable to parameter `created_by_role` with type `CreatorUserRole` in function `models.model.UploadFile.__init__` [bad-argument-type]
|
Contributor
Pyrefly Type Coverage
|
fatelei
approved these changes
Sep 11, 2026
5 tasks done
2 of 5 tasks
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
completed_segmentsandtotal_segmentsfor indexing-status responses with one grouped query keyed by document ownership.RE_SEGMENTexclusion, completed-at semantics, and tenant/dataset ownership filtering.Fixes #42188
Motivation and scope
The web UI polls batch indexing status every 2.5 seconds. The previous implementation executed two
COUNT(DocumentSegment.id)queries inside the response loop for every document. This made the segment-count query count grow as2Nfor a batch ofNdocuments.This change is limited to the indexing-status endpoints. It does not change the document-list endpoint addressed by #40123 and #40125, and it does not depend on that still-open PR.
Verification evidence
Environment: Linux, CPython 3.12.14, SQLAlchemy SQLite test engine, using real controller methods and database rows. No Docker or external service was required for this query-count verification. The measurement verifies query shape and returned values; it is not a production latency benchmark.
The same harness populated 1, 5, and 20 documents with three segments per document and counted emitted
SELECTstatements:indexing-status1 + 2N)indexing-statussegment-count phase2N)indexing-statussegment-count phase2N)After-fix harness output was:
The Service API total includes its unchanged dataset lookup; the batch document lookup was isolated in the harness so the status phase could be measured separately. The console batch document lookup is likewise unchanged.
The regression tests also verify that each document keeps its completed and total counts, and that
RE_SEGMENTrows and rows belonging to another tenant are excluded.Screenshots
Not applicable (backend-only change).
Tests
DEBUG=false uv run --project api python -m pytest -o addopts='' api/tests/unit_tests/controllers/console/datasets/test_datasets.py api/tests/unit_tests/controllers/console/datasets/test_datasets_document.py api/tests/unit_tests/controllers/service_api/dataset/test_document.py -q— 255 passed.make check— passed.uv run --project api --dev ruff format --check ./api— 3523 files already formatted.make api-contract-lint— 528 valid, 0 mismatch, 0 refactorable.uv run --directory api --dev lint-imports— 31 contracts kept, 0 broken.make type-check— no issues found in 1796 source files.Checklist