Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
None of Tracker module's responses set cache tags, i.e. none of tracker.pages.inc
.
Uncovered by #2429617: Make D8 2x as fast: Dynamic Page Cache: context-dependent page caching (for *all* users!).
Proposed resolution
Apply the patch in #2429617-57: Make D8 2x as fast: Dynamic Page Cache: context-dependent page caching (for *all* users!), notice how the tests in TrackerTest
fail. Update tracker.pages.inc
to add cache tags.
Remaining tasks
Work on the proposed resolution.
User interface changes
None.
API changes
None.
Comment | File | Size | Author |
---|---|---|---|
#24 | tracker_responses_don_t-2484611-24.patch | 4.33 KB | borisson_ |
#24 | interdiff.txt | 1.4 KB | borisson_ |
#20 | 2484611-tracker_cache_tags-20-interdiff.txt | 5.08 KB | Berdir |
#20 | 2484611-tracker_cache_tags-20.patch | 4.93 KB | Berdir |
#20 | 2484611-tracker_cache_tags-20-smartcache.patch | 40.79 KB | Berdir |
Comments
Comment #1
Wim LeersComment #2
Wim LeersComment #3
Wim LeersComment #4
jhedstromHere's a start, it doesn't get all of the tracker tests green with the patch from #2429617: Make D8 2x as fast: Dynamic Page Cache: context-dependent page caching (for *all* users!), but drops the fails from 7 to 5.
Comment #5
Wim LeersThanks, great start! :)
This can be simplified to:
$cache_tags = Cache::mergeTags($cache_tags, $node->getCacheTags())
.i.e. no need to manually construct cache tags, especially not if you have the entity objects already anyway. Just call
$entity->getCacheTags()
:)Comment #6
jhedstromThat makes sense, I thought manually creating the tag seemed weird :)
The remaining fails appear to be related to a) new nodes, and b) comment changes. I'm not sure how to bubble up cache tags for either of those (especially since the comments aren't all loaded, just counts of new ones for these pages).
Comment #7
Wim LeersTo track new nodes being created, you'll want to associate the "list" cache tag for the Node entity type. Look at
\Drupal\book\Controller\BookController::bookRender()
for an example.The comment count tracking may be a difficult bit; let's hold off on that for now.
What you can also already do in the mean time, is update the test coverage to verify that the expected cache tags exist. For
WebTestBase
-based tests, we have theassertCacheTag()
method to make that easy.Comment #8
jhedstromThis adds tests, and the list cache tag. Remaining 3 fails seem related to comments.
Comment #10
Wim LeersAwesome, thanks!
For the comment stuff, we have #2082315: Tracker history markers ("new" and "updated" markers, "x new replies" links) forces render caching to be per user. Let's get this in already; that comment stuff is a different can of worms :)
Comment #11
dawehnerShould we not also add the information coming from node access cache contexts?
Comment #12
Wim LeersLet's do that in this issue, yes.
@jhedstrom:
Note the
->addTag('node_access')
bit — that means access checking happens. Which means the overall result must also geti.e. "the output depends on the 'view' node grants" cache context.
Comment #13
fgmRerolled for node access context.
Comment #15
fgmActually, context is really there when checked manually, but most of the contexts disappear in the test, possibly in relation with #2450993: Rendered Cache Metadata created during the main controller request gets lost, so rerolled without this assertion.
Comment #16
fgmComment #17
Wim Leers#15: hrm, there is no
drupal_render()
happening in the Tracker code, so'user.node_grants:view'
should be showing up.Comment #18
fgmThe thing is, the header do show up when looking a the page in a browser, but during a webtest, only about half of the cache-contexts actually make it to the test browser, so this is apparently unrelated to this issue, but to something with the cache contexts handling in general.
Comment #19
jhedstromI can confirm in manual testing of #13 that the appropriate cache context does appear, but during a webtest, only 4 cache contexts are present. I tried adding both
user
andnode
modules toTrackerTest::$modules
, but neither resolved the issue.Comment #20
BerdirActually, the contexts work fine for me, but there's a user cache context on the user tracker (I have no idea what is adding it, though, seems like it should exist on both pages?) and the node grants cache context is part of that and merged.
Also changed the asserts to use the multiple methods from the trait. I find those much easier to work with. Note that the assert(No)CacheTag() actually doesn't have a second argument, so all those assertion messages were ignored anyway.
And added cache tags for the node owners as well, in case e.g. the user name changes.
Note that there's very limited test coverage for the per-user stuff, for example, depending on user access, the user name is linked or not. which is fine as long as it's just permission but if you have custom access checks about something else...
And... like @jhodgdon said in the big meta issue, this uses an "time ago" output. Which means that we really can't cache it if we're honest.
Issues/rabbitholes like this one are why I'm still very worried about smartcache being enabled by default. Maybe we should just mark tracker pages as non-cacheable.
Anyway, here's what I have ;)
Comment #22
Wim LeersIt'll force us to actually fix these issues, rather than ignore them. Being forced to think about (and fix) cacheability is a great problem to have.
We'll want to remove this :)
Due to it being implied by the user context.
Once those are fixed, this is RTBC IMO.
Comment #23
Wim LeersComment #24
borisson_Fixed both issues from #22.
Comment #25
Fabianx CreditAttribution: Fabianx as a volunteer and at Tag1 Consulting commentedRTBC, Looks great!
Comment #28
Fabianx CreditAttribution: Fabianx as a volunteer and at Tag1 Consulting commentedRe-testing due to random test failure.
Comment #31
BerdirSetting back to RTBC, testbot was buggy again.
Comment #32
alexpottThis issue addresses a major bug and is allowed per https://www.drupal.org/core/beta-changes. Committed b497d61 and pushed to 8.0.x. Thanks!
Comment #34
Wim LeersHurray, this brings #2429617: Make D8 2x as fast: Dynamic Page Cache: context-dependent page caching (for *all* users!) closer again!