Problem/Motivation
A number of things happened in core, especially the cacheablity of block access and visibility conditions so that page manager can cache the whole page including access checks *and* become compatible with smartcache.
Proposed resolution
Simplify the cache metadata building, no longer add every visible block to the page cache tag.
Additionally, we'll also need to somehow add the cacheablity metadata of visiblity conditions, similar to BlockAccessControlHandler (both for the display selection and for block access when it is added back).
Remaining tasks
User interface changes
API changes
Data model changes
Comments
Comment #1
berdirHere's a POC patch, haven't updated the tests yet.
Comment #5
berdirI'm so glad I waited for the prophesize patch :) This was a million times easier to debug and fix. Someone needs to update EntityManagerTest to use this :)
This patch
* Fixes the unit tests.
* Since the big if is gone, merges the two test methods together again and makes one block accessible and the other one not.
* Uses the new and awesome addCacheableDependency()
* Optimizes page cacheability metadata by merging block cacheability metadata to avoid cache redirects.
* Adds a bunch of comments, mostly in the test to explain what's going on and why things are expected the way they are.
Comment #7
berdirThat's why we need integration tests :p such stupid. As I said, never actually tried this ;)
Comment #8
wim leersSounds great :)
Why have a
$cacheabilityvariable if you can just apply it to the underlying render array?Every one of these should become:
What am I missing?
<3
+1000 for
prophesize()!s/is/of/
"merged into" -> into what?
Comment #10
berdir2. As discussed, one important reason is unit tests. We'd have to mock that whole method to work like it really does. Also, I simply don't like that API, it creates two cacheability metadata objects, clones one and then merges everything together. addCacheableDependency() is so much nicer and faster. And we're possibly creating a quite a lot of blocks here.
3. Slightly improved the comment. It is merged into the page-level #cache array, which is "page cacheability metadata", would like to avoid repeating that.
Comment #11
berdirVery weird double post.
Comment #12
berdirOpened a follow-up: #2558261: Move code in BlockDisplayVariant::build() to a #pre_render.
Would be nice to get this in so I can work on that. As commented there, this would give me a 20% performance improvement for a specific page in a project.
Comment #13
wim leersNit: By "the whole display", you really mean "this entire function", right? Perhaps the @todo really belongs in
build()'s docs?s/$cacheability/$page_cacheability/, to make it clearer what you're calculating the cacheability of?
Sounds awesome!
Comment #14
dsnopekI haven't tested this but a quick read through the patch looks great! I think this will also simplify the patch on #2511570: Remove Drupal\page_manager\Plugin\PageAwareVariantInterface. So, RTBC+1!
Comment #15
tim.plunkettConflicted with #2550815: BlockDisplayVariant::buildBlock() must check emptyness with Element::isEmpty(), can I get a reroll?
Comment #16
berdirWith pleasure! ;)
The other test method was between the two that were merged together again here. That confused git quite a bit ;)
Comment #17
tim.plunkettThanks!
Comment #21
tim.plunkett