Skip to content

Segment list still signs content file links with one query per segment (N+1) #45252

Open

Description

@cty-ut

Self Checks

  • I have read the Contributing Guide and Language Policy.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report, otherwise it will be closed.
  • 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?

  • I am interested in contributing to this feature.

Activity

  1. added
    💪 enhancement
    on Nov 1, 2026
  2. github-actions commented on Nov 17, 2026

    @github-actions
    Contributor

    Closed due to inactivity. If you have any questions, you can reopen it.

  3. added
    no-issue-activity
    on Nov 17, 2026
  4. added
    👻 feat:rag
    on Nov 20, 2026
  5. removed
    no-issue-activity
    on Nov 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    👻 feat:rag💪 enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions