Skip to content

Commit 752b122

Browse files
committed
Extract awareness transient key into helper with md5 safeguard
1 parent 1c0a959 commit 752b122

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

src/wp-includes/collaboration/class-wp-sync-table-storage.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function add_update( string $room, $update ): bool {
7171
* @return array<int, mixed> Awareness state.
7272
*/
7373
public function get_awareness_state( string $room ): array {
74-
$awareness = get_transient( 'sync_awareness_' . $room );
74+
$awareness = get_transient( $this->get_awareness_transient_key( $room ) );
7575

7676
if ( ! is_array( $awareness ) ) {
7777
return array();
@@ -211,9 +211,25 @@ public function remove_updates_before_cursor( string $room, int $cursor ): bool
211211
* @param array<int, mixed> $awareness Serializable awareness state.
212212
* @return bool True on success, false on failure.
213213
*/
214+
/**
215+
* Returns the transient key used to store awareness state for a room.
216+
*
217+
* The room name is hashed with md5 to guarantee the key stays within
218+
* the 172-character limit imposed by the wp_options option_name column
219+
* (varchar 191 minus the 19-character `_transient_timeout_` prefix).
220+
*
221+
* @since 7.0.0
222+
*
223+
* @param string $room Room identifier.
224+
* @return string Transient key.
225+
*/
226+
private function get_awareness_transient_key( string $room ): string {
227+
return 'sync_awareness_' . md5( $room );
228+
}
229+
214230
public function set_awareness_state( string $room, array $awareness ): bool {
215231
// Awareness is high-frequency, short-lived data (cursor positions, selections)
216232
// that doesn't need cursor-based history. Transients avoid row churn in the table.
217-
return set_transient( 'sync_awareness_' . $room, $awareness, MINUTE_IN_SECONDS );
233+
return set_transient( $this->get_awareness_transient_key( $room ), $awareness, MINUTE_IN_SECONDS );
218234
}
219235
}

0 commit comments

Comments
 (0)