Skip to content

fix(controller): cap answers rendered into the server-side page - #1574

Open
culfin wants to merge 1 commit into
apache:mainfrom
Besser-Sehen-Landshut:fix/ssr-answer-page-size
Open

fix(controller): cap answers rendered into the server-side page#1574
culfin wants to merge 1 commit into
apache:mainfrom
Besser-Sehen-Landshut:fix/ssr-answer-page-size

Conversation

@culfin

@culfin culfin commented Aug 18, 2026

Copy link
Copy Markdown

The question template fetches 999 answers, then the comments for all of them, regardless of how many the page will show. The value is a literal in the controller, so there is no way to lower it:

answerReq := &schema.AnswerListReq{
    QuestionID: id,
    Page:       1,
    PageSize:   999,
}

Measured on a question with 999 answers, against 0.2 s for an ordinary one:

HTML ready on the server 2.6 s
first answer visible in the browser 23.5 s

Most of that is spent parsing 878 KB of HTML and hydrating a thousand posts.

Proposed Changes

  • replace the literal with a named constant of 100 and document what the number is for

This is a mitigation, not a fix

The template renders whatever it is given and has no pagination, so any value here trades page weight against how much of a long question a crawler gets to see. 100 is a compromise: of 7382 questions in my forum only 30 have more than a hundred answers, so for all the others nothing changes at all.

The real fix is to paginate the template page the way the question list already does — bind the page from the query and render ui/template/page.html, which exists and is used elsewhere. That is a larger change touching both the controller and the template, so I did not want to submit it unasked. Happy to prepare it as a follow-up if you prefer that route.

Related: #1573 does the same for the client-side request.

The question template fetches 999 answers and then the comments for all
of them, regardless of how many the page will show. The value is a
literal in the controller, so there is no way to lower it:

  internal/controller/template_controller.go
    answerReq := &schema.AnswerListReq{
        QuestionID: id,
        Page:       1,
        PageSize:   999,
    }

Measured on a question with 999 answers, against 0.2s for an ordinary
question:

  HTML ready on the server        2.6s
  first answer visible in browser 23.5s

Most of that time is spent parsing 878 KB of HTML and hydrating a
thousand posts.

This replaces the literal with a named constant of 100 and explains what
the number is for. It is a mitigation, not a fix: the template renders
whatever it is given and has no pagination, so any value here is a
trade-off between page weight and how much of a long question a crawler
gets to see.

The real fix is to paginate the template page the way the question list
already does — bind the page from the query and render ui/template/page.html.
Happy to prepare that as a follow-up if maintainers prefer it.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@LinkinStars
LinkinStars self-requested a review August 18, 2026 09:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant