Segment list still signs content file links with one query per segment (N+1)
Self Checks
- [x] I have read the Contributing Guide and Language Policy.
- [x] I have searched for existing issues search for existing issues, including closed ones.
- [x] I confirm that I am using English to submit this report, otherwise it will be closed.
- [x] Please do not modify this template :) and fill in all the required fields.
1. Is this request related to a challenge you're experiencing? Tell me about your story.
Follow-up to #45048 / #45050.
#45050 batched the segment list's child chunk and attachment queries, but signing file links in segment content still runs once per segment. For each segment whose content contains /files/... links, sign_segment_content looks up which referenced files the current caller may access, then re-signs those links. Called in a loop over the page, this issues one lookup per segment, so a document with many image-bearing segments (common for PDFs and Word files with images) still hits the database once per segment.
Measured on the unit-test SQLite database, with one image link per segment:
| Path | 1 segment | 20 segments |
|---|---|---|
Console list_segments |
8 queries | 27 queries |
Service API load_segment_details |
5 queries | 24 queries |
2. Additional context or comments
Proposal: collect the file IDs referenced by every segment on the page, check access once per tenant, then sign each segment's links against its own tenant's result.
This keeps the existing access checks. The lookup only depends on the tenant and the current file-access scope, not on which segment references the file, so checking the page's IDs together gives the same result as checking them segment by segment. sign_segment_content stays as is for single-segment and retrieval callers.
I have a PR ready for this.
3. Can you help us with this feature?
- [x] I am interested in contributing to this feature.
Closed due to inactivity. If you have any questions, you can reopen it.
Closing this: #44483 now resolves content file access once per segment page, so the N+1 is already fixed on main.