Repository navigation
perf(api): batch segment list child chunks and attachments - #45050
Conversation
Pyrefly Type Coverage
|
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #45050 +/- ##
==========================================
- Coverage 89.55% 89.55% -0.01%
==========================================
Files 6013 6013
Lines 377204 377239 +35
Branches 76362 76371 +9
==========================================
+ Hits 337811 337840 +29
- Misses 33400 33405 +5
- Partials 5993 5994 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
JohnJyong
left a comment
There was a problem hiding this comment.
No issues found in 9e6348c. Reviewed the console and Service API list/detail paths, relation ownership filters, child-chunk ordering, and full-document behavior.
Validation: 173 related repository, controller, and response-schema tests passed. Seven additional local checks passed for empty input, iterator input, single-detail responses, and hierarchical/automatic/custom processing modes. Ruff lint/format checks and scoped Pyrefly checks passed. The CI checks for this revision are green.
Important
Fixes #<issue number>.Summary
Fixes #45048
Segment lists loaded child chunks and attachments one segment at a time, so the query count grew with the page size. This PR loads them for the whole page with a fixed number of queries.
SegmentReadBatchandload_segment_read_batchindataset_read_repository.py. For a page of segments, it loads their documents, process rules, child chunks and attachment files with oneINquery each, keeping the existing tenant / dataset / document ownership conditions.list_segments,_detail) and Service API (load_segment_details,load_segment_detail) now read child chunks and attachments from the batch.load_segment_detailkeeps its signature for the existing controller callers and builds a single-segment batch when none is passed.parent_modeis notfull-doc, ordered byposition, the same as before.Not changed in this PR:
sign_segment_contentstill queries per segment when the content contains file links. That path applies file access control, so I'd prefer to batch it separately.Screenshots
Queries per page load, hierarchical document, one child chunk and one attachment per segment:
list_segmentsload_segment_detailsTests
test_list_segments_query_count_is_bounded_for_hierarchical_documentsandtest_segment_page_load_is_bounded_for_hierarchical_documents: the query count for 20 segments equals the count for 1. Both fail without this change.test_segment_read_batch_assigns_relations_to_their_segments: child chunks are ordered by position and assigned to their own segment, and an attachment from another tenant is excluded.Checklist
make lint && make type-check(backend) andvp staged(frontend) to appease the lint gods