Skip to content

Rebased: Suspend calling wp_cache_set_posts_last_changed() when touching post meta in WP_Sync_Post_Meta_Storage#11320

Open
chriszarate wants to merge 6 commits intoWordPress:trunkfrom
chriszarate:fix/rtc-suspended-posts-last-changed-update
Open

Rebased: Suspend calling wp_cache_set_posts_last_changed() when touching post meta in WP_Sync_Post_Meta_Storage#11320
chriszarate wants to merge 6 commits intoWordPress:trunkfrom
chriszarate:fix/rtc-suspended-posts-last-changed-update

Conversation

@chriszarate
Copy link

This is a rebased version of @westonruter's #11002 with conflicts fixed.


Trac ticket: https://core.trac.wordpress.org/ticket/64696

Use of AI Tools

Gemini CLI authored a commit to help add phpdoc for the with_suspended_posts_last_changed_update() method.

@github-actions
Copy link

github-actions bot commented Mar 20, 2026

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props westonruter, czarate, zieladam, tyxla.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions
Copy link

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

* @return T Return value from the callback.
*/
private function with_suspended_posts_last_changed_update( Closure $callback ) {
$GLOBALS['__suspend_posts_last_changed_update'] = true;
Copy link
Contributor

@adamziel adamziel Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! I'd just use a counter here, such as

Suggested change
$GLOBALS['__suspend_posts_last_changed_update'] = true;
++$GLOBALS['__suspend_posts_last_changed_update'];

and later on

		--$GLOBALS['__suspend_posts_last_changed_update'];

with a check such as

		0 === $GLOBALS['__suspend_posts_last_changed_update']

just in case there's a call inside a call for whatever weird reason.

try {
return $callback();
} finally {
$GLOBALS['__suspend_posts_last_changed_update'] = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also update this one if we end up using it as a counter

// update_post_meta returns false if the value is the same as the existing value.
update_post_meta( $post_id, wp_slash( self::AWARENESS_META_KEY ), wp_slash( $awareness ) );
$this->with_suspended_posts_last_changed_update(
fn() => update_post_meta( $post_id, self::AWARENESS_META_KEY, wp_slash( $awareness ) )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need that private method actually? Or should we just inline it here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we don't inline it, then we can avoid the need for try/catch and a counter approach, so probably worth it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the try/catch is extra safe, though, so i'll keep it

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if I follow how could we avoid try/catch and a counter – do you mean we can avoid duplicating that code in two places? Yeah that sounds good to me. Or do you mean we could avoid that entirely? In which case I'm super curious.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignore this, I was misunderstanding what you meant by "call inside of a call"

@adamziel
Copy link
Contributor

Also, this change touches a pretty central data flow – can we add a few tests for this to be sure it doesn't regress over time?

@chriszarate
Copy link
Author

Also, this change touches a pretty central data flow – can we add a few tests for this to be sure it doesn't regress over time?

Unit tests added in dc85bf7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants