From 6ce65468c0c664bce3b34ae57a7fb218ecf04073 Mon Sep 17 00:00:00 2001 From: Peter Wilson Date: Tue, 3 Mar 2026 10:58:45 +1100 Subject: [PATCH 1/6] Use transients for awareness state (KISS approach). --- .../collaboration/class-wp-sync-post-meta-storage.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/wp-includes/collaboration/class-wp-sync-post-meta-storage.php b/src/wp-includes/collaboration/class-wp-sync-post-meta-storage.php index d0f1c99736fe0..a073946e8708b 100644 --- a/src/wp-includes/collaboration/class-wp-sync-post-meta-storage.php +++ b/src/wp-includes/collaboration/class-wp-sync-post-meta-storage.php @@ -123,6 +123,10 @@ static function ( $update ): bool { return $updates; } + public function get_awareness_cache_key( $post_id ) { + return self::AWARENESS_META_KEY . '_' . $post_id; + } + /** * Gets awareness state for a given room. * @@ -137,7 +141,7 @@ public function get_awareness_state( string $room ): array { return array(); } - $awareness = get_post_meta( $post_id, self::AWARENESS_META_KEY, true ); + $awareness = get_transient( $this->get_awareness_cache_key( $post_id ) ); if ( ! is_array( $awareness ) ) { return array(); @@ -161,8 +165,7 @@ public function set_awareness_state( string $room, array $awareness ): bool { return false; } - // update_post_meta returns false if the value is the same as the existing value. - update_post_meta( $post_id, self::AWARENESS_META_KEY, $awareness ); + set_transient( $this->get_awareness_cache_key( $post_id ), $awareness, HOUR_IN_SECONDS ); return true; } From b097d00f3623fdc8ea44924004ad570bfa8b7a65 Mon Sep 17 00:00:00 2001 From: Peter Wilson Date: Tue, 3 Mar 2026 11:09:01 +1100 Subject: [PATCH 2/6] Rename constant for accuracy. --- .../collaboration/class-wp-sync-post-meta-storage.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/wp-includes/collaboration/class-wp-sync-post-meta-storage.php b/src/wp-includes/collaboration/class-wp-sync-post-meta-storage.php index a073946e8708b..0b19264551955 100644 --- a/src/wp-includes/collaboration/class-wp-sync-post-meta-storage.php +++ b/src/wp-includes/collaboration/class-wp-sync-post-meta-storage.php @@ -25,12 +25,12 @@ class WP_Sync_Post_Meta_Storage implements WP_Sync_Storage { const POST_TYPE = 'wp_sync_storage'; /** - * Meta key for awareness state. + * Transient prefix for awareness state. * * @since 7.0.0 * @var string */ - const AWARENESS_META_KEY = 'wp_sync_awareness'; + const AWARENESS_TRANSIENT_PREFIX = 'wp_sync_awareness'; /** * Meta key for sync updates. @@ -124,7 +124,7 @@ static function ( $update ): bool { } public function get_awareness_cache_key( $post_id ) { - return self::AWARENESS_META_KEY . '_' . $post_id; + return self::AWARENESS_TRANSIENT_PREFIX . '_' . $post_id; } /** From 235d84b8f797d68b3d715511a0d5aa3e79a1299d Mon Sep 17 00:00:00 2001 From: Peter Wilson Date: Tue, 3 Mar 2026 11:12:21 +1100 Subject: [PATCH 3/6] Safety, possibly not needed. --- .../collaboration/class-wp-sync-post-meta-storage.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/collaboration/class-wp-sync-post-meta-storage.php b/src/wp-includes/collaboration/class-wp-sync-post-meta-storage.php index 0b19264551955..3092e9845b25b 100644 --- a/src/wp-includes/collaboration/class-wp-sync-post-meta-storage.php +++ b/src/wp-includes/collaboration/class-wp-sync-post-meta-storage.php @@ -124,7 +124,13 @@ static function ( $update ): bool { } public function get_awareness_cache_key( $post_id ) { - return self::AWARENESS_TRANSIENT_PREFIX . '_' . $post_id; + $cache_key = self::AWARENESS_TRANSIENT_PREFIX . '_' . $post_id; + if ( strlen( $cache_key ) <= 172 ) { + // Safe length for a transient key. + return $cache_key; + } + // If the cache key is too long, hash it to ensure it fits within limits. + return md5( $cache_key ); } /** From d9042521e5e2d9caf52f0f8436080c8e079a5a18 Mon Sep 17 00:00:00 2001 From: Peter Wilson Date: Tue, 3 Mar 2026 11:12:49 +1100 Subject: [PATCH 4/6] Rename method for accuracy. --- .../collaboration/class-wp-sync-post-meta-storage.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/wp-includes/collaboration/class-wp-sync-post-meta-storage.php b/src/wp-includes/collaboration/class-wp-sync-post-meta-storage.php index 3092e9845b25b..d934f35796034 100644 --- a/src/wp-includes/collaboration/class-wp-sync-post-meta-storage.php +++ b/src/wp-includes/collaboration/class-wp-sync-post-meta-storage.php @@ -123,7 +123,7 @@ static function ( $update ): bool { return $updates; } - public function get_awareness_cache_key( $post_id ) { + public function get_awareness_transient_key( $post_id ) { $cache_key = self::AWARENESS_TRANSIENT_PREFIX . '_' . $post_id; if ( strlen( $cache_key ) <= 172 ) { // Safe length for a transient key. @@ -147,7 +147,7 @@ public function get_awareness_state( string $room ): array { return array(); } - $awareness = get_transient( $this->get_awareness_cache_key( $post_id ) ); + $awareness = get_transient( $this->get_awareness_transient_key( $post_id ) ); if ( ! is_array( $awareness ) ) { return array(); @@ -171,7 +171,7 @@ public function set_awareness_state( string $room, array $awareness ): bool { return false; } - set_transient( $this->get_awareness_cache_key( $post_id ), $awareness, HOUR_IN_SECONDS ); + set_transient( $this->get_awareness_transient_key( $post_id ), $awareness, HOUR_IN_SECONDS ); return true; } From 088548b818c1b47fdfdec469d7acd668eea903bb Mon Sep 17 00:00:00 2001 From: Peter Wilson Date: Tue, 3 Mar 2026 11:13:34 +1100 Subject: [PATCH 5/6] Docblock for new method. --- .../collaboration/class-wp-sync-post-meta-storage.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/wp-includes/collaboration/class-wp-sync-post-meta-storage.php b/src/wp-includes/collaboration/class-wp-sync-post-meta-storage.php index d934f35796034..0eb171a768266 100644 --- a/src/wp-includes/collaboration/class-wp-sync-post-meta-storage.php +++ b/src/wp-includes/collaboration/class-wp-sync-post-meta-storage.php @@ -123,6 +123,14 @@ static function ( $update ): bool { return $updates; } + /** + * Gets the transient key for awareness state for a given post ID. + * + * @since 7.0.0 + * + * @param int $post_id Post ID. + * @return string Transient key for awareness state. + */ public function get_awareness_transient_key( $post_id ) { $cache_key = self::AWARENESS_TRANSIENT_PREFIX . '_' . $post_id; if ( strlen( $cache_key ) <= 172 ) { From 81bd3ebbbc3223d6a6338a5da75d9370f9ee4df3 Mon Sep 17 00:00:00 2001 From: Peter Wilson Date: Tue, 3 Mar 2026 12:19:02 +1100 Subject: [PATCH 6/6] Restore comment re: always returning true. --- .../collaboration/class-wp-sync-post-meta-storage.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/wp-includes/collaboration/class-wp-sync-post-meta-storage.php b/src/wp-includes/collaboration/class-wp-sync-post-meta-storage.php index 0eb171a768266..46c0165826fb9 100644 --- a/src/wp-includes/collaboration/class-wp-sync-post-meta-storage.php +++ b/src/wp-includes/collaboration/class-wp-sync-post-meta-storage.php @@ -179,6 +179,7 @@ public function set_awareness_state( string $room, array $awareness ): bool { return false; } + // set_transient() can return false if the value is the same as the existing value, which is considered a success regardless. set_transient( $this->get_awareness_transient_key( $post_id ), $awareness, HOUR_IN_SECONDS ); return true; }