Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Wim Leers created an issue. See original summary.

Wim Leers’s picture

Title: Improve comments in Renderer::shouldAutomaticallyPlaceholder() » Improve comments in Renderer::shouldAutomaticallyPlaceholder() and DynamicPageCacheSubscriber

Assuming #2429617: Make D8 2x as fast: Dynamic Page Cache: context-dependent page caching (for *all* users!) lands, this is what the title should be. We'll need to make the same fixes in both places.

borisson_’s picture

Status: Active » Needs review
FileSize
3.51 KB

Initial take on the updated comments.

borisson_’s picture

Issue tags: +rc eligible
lauriii’s picture

Status: Needs review » Reviewed & tested by the community

Docs look good for me. Maybe someone wants to double check the wording? Setting anyway to RTBC.

joelpittet’s picture

The wording is good though verbose but I think it needs it. RTBC++

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 3: improve_comments_in-2564577-3.patch, failed testing.

The last submitted patch, 3: improve_comments_in-2564577-3.patch, failed testing.

snehi’s picture

So here is the review
1. Can we replace this line with

Auto-placeholder if a cache context is set that is set in the

with

Auto-placeholder if a cache context is in the

2.

+    // These are cache contexts with high cardinality that are deemed to have
              +    // such high cardinality that there would be too much pollution in the

How many that in this lines.

3. Can i know what has been changed in this line

--- a/core/modules/dynamic_page_cache/src/EventSubscriber/DynamicPageCacheSubscriber.php
+++ b/core/modules/dynamic_page_cache/src/EventSubscriber/DynamicPageCacheSubscriber.php
@@ -221,7 +221,7 @@ public function onResponse(FilterResponseEvent $event) {
    * bubbling to the response level: while rendering, the Renderer checks every
    * subtree to see if meets the auto-placeholdering conditions. If it does, it
    * is automatically placeholdered, and consequently the cacheability metadata
-   * of the placeholdered content does not bubble up to the response level. 
+   * of the placeholdered content does not bubble up to the response level.

Wim Leers’s picture

Title: Improve comments in Renderer::shouldAutomaticallyPlaceholder() and DynamicPageCacheSubscriber » Improve comments on PlaceholderGeneratorInterface::shouldAutomaticallyPlaceholder() and DynamicPageCacheSubscriber::shouldCacheResponse()
Issue tags: +Documentation
  1. +++ b/core/lib/Drupal/Core/Render/Renderer.php
    @@ -661,12 +661,20 @@ protected function shouldAutomaticallyPlaceholder(array $element) {
    +    // Auto-placeholder if a cache context is set that is set in the
    ...
    +    // Auto-placeholder if a cache tag is set that is set in the
    

    Agreed with #9 that this is very confusing.

    Note that this has now moved to \Drupal\Core\Render\PlaceholderGeneratorInterface::shouldAutomaticallyPlaceholder(). I think it's better to document it on that interface now, and not in the actual implementation.

  2. +++ b/core/modules/dynamic_page_cache/src/EventSubscriber/DynamicPageCacheSubscriber.php
    @@ -221,7 +221,7 @@ public function onResponse(FilterResponseEvent $event) {
    @@ -241,12 +241,20 @@ protected function shouldCacheResponse(CacheableResponseInterface $response) {
    

    I'm not sure I understand why the comments in here need to be updated.

    Why isn't \Drupal\dynamic_page_cache\EventSubscriber\DynamicPageCacheSubscriber::shouldCacheResponse()'s documentation sufficient?

    And perhaps we can make DynamicPageCacheSubscriber::shouldCacheResponse() call PlaceholderGeneratorInterface:;shouldAutomaticallyPlaceholder()? And move the docs from the former to the latter, and improve it. Then all docs and all logic live in a single canonical place. That seems better :)

lauriii’s picture

Status: Needs work » Needs review
FileSize
2.17 KB

Tried to fix #1. I removed doc changes for #2 because it has good docs in the docblock.

Wim Leers’s picture

  1. +++ b/core/lib/Drupal/Core/Render/PlaceholderGenerator.php
    @@ -56,12 +56,20 @@ public function shouldAutomaticallyPlaceholder(array $element) {
    -    // Auto-placeholder if a high-cardinality cache context is set.
    +    // Auto-placeholder if a cache context is in the
    +    // renderer.config.auto_placeholder_conditions.contexts configuration array.
    +    // These are cache contexts with high cardinality that are deemed to have
    +    // such high cardinality that there would be too much pollution in the
    +    // configured cache-bin.
         if (isset($element['#cache']['contexts']) && array_intersect($element['#cache']['contexts'], $conditions['contexts'])) {
           return TRUE;
         }
     
    -    // Auto-placeholder if a high-invalidation frequency cache tag is set.
    +    // Auto-placeholder if a cache context is in the
    +    // renderer.config.auto_placeholder_conditions.tags configuration array.
    +    // These are cache tags with high cardinality that are deemed to have
    +    // such high invalidation rate that there would be too much cache
    +    // invalidation for the configured cache-bin.
    

    I think #10.1 still applies here: I think it's better to document it on that interface now, and not in the implementation.

    i.e. move basically this into the second hunk?

  2. +++ b/core/lib/Drupal/Core/Render/PlaceholderGeneratorInterface.php
    @@ -35,6 +35,10 @@ public function canCreatePlaceholder(array $element);
    +   * Render array should be placeholdered if its cacheable metadata would create
    

    s/cacheable/cacheability/

snehi’s picture

Doing as suggested in 12.2. @Wim Leers Can you please explain what to do in 12.1.

Wim Leers’s picture

Status: Needs review » Needs work

#13:

I already explained #12.1?

Also, your change causes it to go beyond 80 characters; those lines need to be reflowed.

Wim Leers’s picture

  1. +++ b/core/lib/Drupal/Core/Render/PlaceholderGenerator.php
    @@ -56,12 +56,20 @@ public function shouldAutomaticallyPlaceholder(array $element) {
    +    // These are cache contexts with high cardinality that are deemed to have
    

    s/with high cardinality/

  2. +++ b/core/lib/Drupal/Core/Render/PlaceholderGenerator.php
    @@ -56,12 +56,20 @@ public function shouldAutomaticallyPlaceholder(array $element) {
    +    // such high cardinality that there would be too much pollution in the
    

    s/such high/such a high/

  3. +++ b/core/lib/Drupal/Core/Render/PlaceholderGenerator.php
    @@ -56,12 +56,20 @@ public function shouldAutomaticallyPlaceholder(array $element) {
    +    // configured cache-bin.
    

    s/configured cache-bin/cache bin that would make caching ineffective/

  4. +++ b/core/lib/Drupal/Core/Render/PlaceholderGenerator.php
    @@ -56,12 +56,20 @@ public function shouldAutomaticallyPlaceholder(array $element) {
    +    // These are cache tags with high cardinality that are deemed to have
    

    s/with high cardinality//

  5. +++ b/core/lib/Drupal/Core/Render/PlaceholderGenerator.php
    @@ -56,12 +56,20 @@ public function shouldAutomaticallyPlaceholder(array $element) {
    +    // such high invalidation rate that there would be too much cache
    

    s/such high/such a high/

  6. +++ b/core/lib/Drupal/Core/Render/PlaceholderGenerator.php
    @@ -56,12 +56,20 @@ public function shouldAutomaticallyPlaceholder(array $element) {
    +    // invalidation for the configured cache-bin.
    

    s/configured cache-bin/cache bin that would make caching ineffective/

  7. +++ b/core/lib/Drupal/Core/Render/PlaceholderGeneratorInterface.php
    @@ -35,6 +35,10 @@ public function canCreatePlaceholder(array $element);
    +   * Render array should be placeholdered if its cacheability metadata would create
    

    80 cols violation.

    s/Render array/The render array/

    s/metadata//

    s/create/have/

  8. +++ b/core/lib/Drupal/Core/Render/PlaceholderGeneratorInterface.php
    @@ -35,6 +35,10 @@ public function canCreatePlaceholder(array $element);
    +   * either too high cardinality or too high invalidation rate in the configured
    +   * cache-bin.
    

    s/in the configured cache-bin//

snehi’s picture

Status: Needs work » Needs review
FileSize
2.14 KB
2.52 KB

Thanks for your review.
Done the changes.

Wim Leers’s picture

Status: Needs review » Needs work
  1. +++ b/core/lib/Drupal/Core/Render/PlaceholderGenerator.php
    @@ -56,12 +56,20 @@ public function shouldAutomaticallyPlaceholder(array $element) {
    +    // These are cache contexts that are deemed to have
    +    // such a high cardinality that there would be too much pollution in the
    +    // cache bin that would make caching ineffective.
    

    80 cols.

  2. +++ b/core/lib/Drupal/Core/Render/PlaceholderGenerator.php
    @@ -56,12 +56,20 @@ public function shouldAutomaticallyPlaceholder(array $element) {
    +    // These are cache tags that are deemed to have
    +    // such a high invalidation rate that there would be too much cache
    +    // invalidation for the cache bin that would make caching ineffective.
    

    80 cols.

  3. +++ b/core/lib/Drupal/Core/Render/PlaceholderGeneratorInterface.php
    @@ -35,6 +35,9 @@ public function canCreatePlaceholder(array $element);
    +   * The render array should be placeholdered if its cacheability would
    +   * have either too high cardinality or too high invalidation rate.
    

    80 cols.

snehi’s picture

Assigned: Unassigned » snehi
r_sharma08’s picture

Status: Needs work » Needs review
FileSize
1.2 KB

Applied patch for Sr. #1 and #2.
For #3, it is not required to change.
Please review.

Status: Needs review » Needs work

The last submitted patch, 19: 2564577.patch, failed testing.

joelpittet’s picture

@Wim Leers I think you may have accidently reviewed the wrong patch I checked #16 and it's within 80chars.

@r_sharma08 it's a weird to have fails on comments but why is it not required? None of #16 is in there and it looks like @snehi assigned it to himself so I believe he was going to work on it.

rakesh.gectcr’s picture

@snehi,

Hope the above comment #21 from @joelpittet , understands you well enough, Because I told you this before.

Looks like @r_sharma08 also your colleague. I have seen couple of other colleagues of yours are doing the same mistakes. But seems like you are well active in the community and doing good job, really appreciating that.

So can you please guide(or mentor) your colleagues to get familiar with right works flows on behalf our community. Please consider this as my humble request.

r_sharma08’s picture

Assigned: snehi » r_sharma08
r_sharma08’s picture

Status: Needs work » Needs review

#16 is OK. Changing status.

Status: Needs review » Needs work

The last submitted patch, 19: 2564577.patch, failed testing.

borisson_’s picture

Assigned: r_sharma08 » borisson_
Status: Needs work » Needs review
FileSize
2.49 KB
2.14 KB

Attached interdiff based on #16 - this fixes the remarks made in #17.

@joelpittet, in #21 you mention that everything was within the 80 cols limit, while that was true, we're supposed to wrap as close to 80 cols as possible. This needed some reflow of the documentation.

From [#1354]:

Lines containing comments (including docblocks) must wrap as close to 80 characters as possible without going over, with a few exceptions (noted in the Tag Reference below).

Wim Leers’s picture

#21: I didn't mean it exceeded 80 characters, I meant it didn't *use* 80 characters: there is lots of bizarre whitespace left open.

Reroll attached that I think is much simpler and addresses all concerns raised here.

Thoughts?


EDIT: crosspost.

#26:

+++ b/core/lib/Drupal/Core/Render/PlaceholderGeneratorInterface.php
@@ -35,6 +35,9 @@ public function canCreatePlaceholder(array $element);
+   * The render array should be placeholdered if its cacheability would* have

Stray asterisk there.

borisson_’s picture

#27 indeed looks much simpler, I'd say we go with that.

Wim Leers’s picture

#28: Care to RTBC then? :)

BTW: also finished the handbook page at https://www.drupal.org/developing/api/8/render/arrays/cacheability/auto-...

borisson_’s picture

Status: Needs review » Reviewed & tested by the community

RTBC it is.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Docs only change - eligible for patch release. Committed 76525d8 and pushed to 8.0.x and 8.1.x. Thanks!

  • alexpott committed df41f70 on 8.1.x
    Issue #2564577 by snehi, borisson_, Wim Leers, r_sharma08, lauriii:...

  • alexpott committed 76525d8 on
    Issue #2564577 by snehi, borisson_, Wim Leers, r_sharma08, lauriii:...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.