Problem/Motivation

The thread render-cache entry inherits its cacheability from the comment index, with three effects:

  • Signed-in markup is never shared. CommentIndexRepository::load() hard-codes the user context (src/CommentIndexRepository.php:192, and :173 for bounded empty results). The context was added for the in-request memo, whose key is already per account (:162-163), not because the index content varies per user. CommentHistory::lazyBuilder() adds user as well (src/Element/CommentHistory.php:49). This is documented in docs/loading-strategies.md Known limitations ("The signed-in thread render cache is per user").
  • Any comment write invalidates every thread on the site. The index adds the global comment_list tag (src/CommentIndexRepository.php:193), which core invalidates on every comment save.
  • Every cache hit validates one tag per comment. For readers without administer comments, core adds one comment:N tag per accessible comment. CommentThreadBuilder::build() merges $slice->cacheability (src/CommentThreadBuilder.php:213), so those tags reach the thread entry. The code comment at :225-231 says per-comment tags are not on it; that comment is wrong.

ADR 0009 phase 3, first bullet.

Proposed resolution

  • Replace comment_list and the per-comment comment:N tags on the thread entry with act_comments:{entity_type}:{entity_id}, invalidated as in #1 (insert, update, delete, both hosts on a move). If this lands before #1, it introduces the tag and the hooks itself. Keep node:N, config and field tags. Per-comment entries in CommentSliceRenderer keep comment:N (src/CommentSliceRenderer.php:125-134).
  • Stop adding user in load(). Keep the per-account memo key. Per-user parts of the slice (approve, edit and delete access, the relocated links) already bubble their own contexts.
  • Fix the misleading comment at CommentThreadBuilder.php:225-231.
  • Later, possibly in a follow-up: placeholder the per-user action links so that authenticated thread HTML varies only by permissions.

Remaining tasks

  • Kernel tests:
    • a write on host A does not invalidate host B's thread;
    • delete and move invalidate the right hosts;
    • two signed-in users with the same roles share a thread entry, but not when an access result declares user;
    • the tag count on the thread entry is independent of the comment count.
  • Audit every consumer of $index->cacheability() for reliance on user.

User interface changes

None.

API changes

New cache tag act_comments:{entity_type}:{entity_id}, documented for sites that need to invalidate it.

Data model changes

None.

Comments

freelock created an issue. See original summary.

freelock’s picture

Title: Thread render cache: use a per-host tag instead of <code>comment_list</code>, and stop hard-coding the <code>user</code> context » Thread render cache: use a per-host tag instead of comment_lis, and stop hard-coding the user context
Issue summary: View changes
freelock’s picture

Title: Thread render cache: use a per-host tag instead of comment_lis, and stop hard-coding the user context » Thread render cache: use a per-host tag instead of comment_list, and stop hard-coding the user context
freelock’s picture

Partially implemented - the per-user variation has been removed, but the global comment_list tag is still included.

freelock’s picture

Status: Active » Needs work

The explicit user context was removed, but `CommentIndexRepository` still adds global comment-list tags. The host-scoped snapshot cache does not finish this render-cache task.