Skip to content

Commit 6ce6546

Browse files
committed
Use transients for awareness state (KISS approach).
1 parent 50d6cf5 commit 6ce6546

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

src/wp-includes/collaboration/class-wp-sync-post-meta-storage.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ static function ( $update ): bool {
123123
return $updates;
124124
}
125125

126+
public function get_awareness_cache_key( $post_id ) {
127+
return self::AWARENESS_META_KEY . '_' . $post_id;
128+
}
129+
126130
/**
127131
* Gets awareness state for a given room.
128132
*
@@ -137,7 +141,7 @@ public function get_awareness_state( string $room ): array {
137141
return array();
138142
}
139143

140-
$awareness = get_post_meta( $post_id, self::AWARENESS_META_KEY, true );
144+
$awareness = get_transient( $this->get_awareness_cache_key( $post_id ) );
141145

142146
if ( ! is_array( $awareness ) ) {
143147
return array();
@@ -161,8 +165,7 @@ public function set_awareness_state( string $room, array $awareness ): bool {
161165
return false;
162166
}
163167

164-
// update_post_meta returns false if the value is the same as the existing value.
165-
update_post_meta( $post_id, self::AWARENESS_META_KEY, $awareness );
168+
set_transient( $this->get_awareness_cache_key( $post_id ), $awareness, HOUR_IN_SECONDS );
166169
return true;
167170
}
168171

0 commit comments

Comments
 (0)