-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Rebased: Suspend calling wp_cache_set_posts_last_changed() when touching post meta in WP_Sync_Post_Meta_Storage
#11320
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
9311711
fba4b2a
4498e29
98b851a
dc85bf7
178a599
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -79,9 +79,9 @@ public function add_update( string $room, $update ): bool { | |||||
| return false; | ||||||
| } | ||||||
|
|
||||||
| $meta_id = add_post_meta( $post_id, self::SYNC_UPDATE_META_KEY, $update, false ); | ||||||
|
|
||||||
| return (bool) $meta_id; | ||||||
| return $this->with_suspended_posts_last_changed_update( | ||||||
| fn() => (bool) add_post_meta( $post_id, self::SYNC_UPDATE_META_KEY, $update, false ) | ||||||
| ); | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
|
|
@@ -123,7 +123,10 @@ public function set_awareness_state( string $room, array $awareness ): bool { | |||||
| } | ||||||
|
|
||||||
| // 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 ) ) | ||||||
| ); | ||||||
|
|
||||||
| return true; | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -299,4 +302,25 @@ public function remove_updates_before_cursor( string $room, int $cursor ): bool | |||||
|
|
||||||
| return true; | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * Invokes the provided callback while the suspending setting the posts | ||||||
| * last_changed cache key via a special global flag. | ||||||
| * | ||||||
| * @since 7.0.0 | ||||||
| * @see wp_cache_set_posts_last_changed() | ||||||
| * | ||||||
| * @template T | ||||||
| * @param Closure(): T $callback Callback. | ||||||
| * @return T Return value from the callback. | ||||||
| */ | ||||||
| private function with_suspended_posts_last_changed_update( Closure $callback ) { | ||||||
| $GLOBALS['__suspend_posts_last_changed_update'] = true; | ||||||
|
||||||
| $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.
Outdated
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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"