Automattic / wp-calypso

The JavaScript and API powered WordPress.com
https://developer.wordpress.com
GNU General Public License v2.0
12.42k stars 1.99k forks source link

[Bug]: post-navigation-link: stale cache after trashing or restoring surrounding posts #70599

Open mreishus opened 1 year ago

mreishus commented 1 year ago

Quick summary

After trashing or restoring blog posts, the post-navigation-link block can still render with outdated cached information when making "<- Previous" or "Next ->" links, as if the trash or restore never happened.

This is on WPCOM Simple and could be related to a caching optimization on the platform. I haven't tried on a standalone .org site.

5754652-zd-woothemes

Steps to reproduce

<!-- wp:template-part {"slug":"header-large-dark","theme":"pub/twentytwentytwo","tagName":"header"} /-->

<!-- wp:group {"tagName":"main"} -->
<main class="wp-block-group"><!-- wp:group {"layout":{"inherit":true,"type":"constrained"}} -->
<div class="wp-block-group"><!-- wp:spacer {"height":"30px"} -->
<div style="height:30px" aria-hidden="true" class="wp-block-spacer"></div>
<!-- /wp:spacer -->

<!-- wp:post-title {"textAlign":"center","level":1,"align":"wide","style":{"spacing":{"margin":{"bottom":"var(\u002d\u002dwp\u002d\u002dcustom\u002d\u002dspacing\u002d\u002dmedium, 6rem)"}}}} /-->

<!-- wp:post-featured-image {"align":"wide","style":{"spacing":{"margin":{"bottom":"var(\u002d\u002dwp\u002d\u002dcustom\u002d\u002dspacing\u002d\u002dmedium, 6rem)"}}}} /-->

<!-- wp:separator {"opacity":"css","className":"alignwide is-style-wide"} -->
<hr class="wp-block-separator has-css-opacity alignwide is-style-wide"/>
<!-- /wp:separator --></div>
<!-- /wp:group -->

<!-- wp:spacer {"height":"32px"} -->
<div style="height:32px" aria-hidden="true" class="wp-block-spacer"></div>
<!-- /wp:spacer -->

<!-- wp:post-content {"layout":{"inherit":true}} /-->

<!-- wp:spacer {"height":"32px"} -->
<div style="height:32px" aria-hidden="true" class="wp-block-spacer"></div>
<!-- /wp:spacer -->

<!-- wp:group {"layout":{"inherit":true,"type":"constrained"}} -->
<div class="wp-block-group"><!-- wp:group {"layout":{"type":"flex"}} -->
<div class="wp-block-group"><!-- wp:post-date {"format":"F j, Y","style":{"typography":{"fontStyle":"italic","fontWeight":"400"}},"fontSize":"small"} /-->

<!-- wp:post-author {"showAvatar":false,"fontSize":"small"} /-->

<!-- wp:post-terms {"term":"category","fontSize":"small"} /-->

<!-- wp:post-terms {"term":"post_tag","fontSize":"small"} /--></div>
<!-- /wp:group -->

<!-- wp:group {"layout":{"type":"flex","flexWrap":"nowrap"}} -->
<div class="wp-block-group"></div>
<!-- /wp:group -->

<!-- wp:columns -->
<div class="wp-block-columns"><!-- wp:column -->
<div class="wp-block-column"><!-- wp:post-navigation-link {"textAlign":"left","type":"previous","label":"← Previous"} /--></div>
<!-- /wp:column -->

<!-- wp:column -->
<div class="wp-block-column"><!-- wp:post-navigation-link {"textAlign":"right","label":"Next →"} /--></div>
<!-- /wp:column --></div>
<!-- /wp:columns -->

<!-- wp:spacer {"height":"32px"} -->
<div style="height:32px" aria-hidden="true" class="wp-block-spacer"></div>
<!-- /wp:spacer -->

<!-- wp:paragraph {"align":"left","fontSize":"medium"} -->
<p class="has-text-align-left has-medium-font-size">Related Posts ↘</p>
<!-- /wp:paragraph -->

<!-- wp:jetpack/related-posts {"displayDate":false,"displayThumbnails":true,"align":"wide"} /-->

<!-- wp:spacer {"height":"32px"} -->
<div style="height:32px" aria-hidden="true" class="wp-block-spacer"></div>
<!-- /wp:spacer -->

<!-- wp:separator {"opacity":"css","className":"is-style-wide"} -->
<hr class="wp-block-separator has-css-opacity is-style-wide"/>
<!-- /wp:separator -->

<!-- wp:comments {"legacy":true} /-->

<!-- wp:block {"ref":83305} /--></div>
<!-- /wp:group --></main>
<!-- /wp:group -->

<!-- wp:template-part {"slug":"footer","theme":"pub/twentytwentytwo","tagName":"footer"} /-->

What you expected to happen

n/a

What actually happened

n/a

Browser

No response

Context

No response

Platform (Simple, Atomic, or both?)

Simple

Other notes

No response

Reproducibility

Consistent

Severity

No response

Available workarounds?

Yes, difficult to implement

Workaround details

A workaround can only be used by A11Ns: Use the special query parameter to clear cache, but this may only fix for one datacenter.

mreishus commented 1 year ago

There is a 48 hour WPCOM specific cache for get_adjacent_post() causing this issue; it's not invalidated for adjacent posts while trashing.

Searching around, it seems this function has performance issues, hence the heavy caching.

mreishus commented 1 year ago

As far as I can tell, there is no cache invalidation for the get_adjacent_post() function.

mreishus commented 1 year ago

The cache was initially added in : p4IuY0-30-p2 and p1YhhO-rV-p2 . Some discussion about invalidation is in there: mostly that it's difficult to solve because of the core design we are wrapping, but setting it to 3 hours was a compromise between performance and correctness, even if invalidation was not solved. Later, this was bumped from 3 hours to 48 hours to solve some performance issues, but invalidation was not addressed.

mreishus commented 1 year ago

Patch idea here, but I'm not certain about it: D93982-code

github-actions[bot] commented 1 year ago

Support References

This comment is automatically generated. Please do not edit it.

AnjanaV93 commented 1 year ago

Another user reported this in 6061696-zen

I can replicate the same behavior on my test site as well using the following themes: