Skip to content

Commit 4e49b46

Browse files
committed
Replace room_hash with human-readable room column in sync_updates table
Store the room identifier string directly instead of its md5 hash. Room strings like "postType/post:42" are short, already validated by the REST API schema, and storing them verbatim improves debuggability.
1 parent 5fa9356 commit 4e49b46

5 files changed

Lines changed: 16 additions & 18 deletions

File tree

src/wp-admin/includes/schema.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,11 +189,11 @@ function wp_get_db_schema( $scope = 'all', $blog_id = null ) {
189189
) $charset_collate;
190190
CREATE TABLE $wpdb->sync_updates (
191191
id bigint(20) unsigned NOT NULL auto_increment,
192-
room_hash char(32) NOT NULL,
192+
room varchar(255) NOT NULL,
193193
update_value longtext NOT NULL,
194194
created_at datetime NOT NULL default '0000-00-00 00:00:00',
195195
PRIMARY KEY (id),
196-
KEY room_hash (room_hash,id)
196+
KEY room (room,id)
197197
) $charset_collate;\n";
198198

199199
// Single site users table. The multisite flavor of the users table is handled below.

src/wp-admin/includes/upgrade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -886,7 +886,7 @@ function upgrade_all() {
886886
upgrade_682();
887887
}
888888

889-
if ( $wp_current_db_version < 61697 ) {
889+
if ( $wp_current_db_version < 61698 ) {
890890
upgrade_700();
891891
}
892892

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

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function add_update( string $room, $update ): bool {
4949
$result = $wpdb->insert(
5050
$wpdb->sync_updates,
5151
array(
52-
'room_hash' => md5( $room ),
52+
'room' => $room,
5353
'update_value' => wp_json_encode( $update ),
5454
'created_at' => current_time( 'mysql', true ),
5555
),
@@ -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_' . md5( $room ) );
74+
$awareness = get_transient( 'sync_awareness_' . $room );
7575

7676
if ( ! is_array( $awareness ) ) {
7777
return array();
@@ -125,13 +125,11 @@ public function get_update_count( string $room ): int {
125125
public function get_updates_after_cursor( string $room, int $cursor ): array {
126126
global $wpdb;
127127

128-
$room_hash = md5( $room );
129-
130128
// Snapshot the current max ID for this room to define a stable upper bound.
131129
$max_id = (int) $wpdb->get_var(
132130
$wpdb->prepare(
133-
"SELECT COALESCE( MAX( id ), 0 ) FROM {$wpdb->sync_updates} WHERE room_hash = %s",
134-
$room_hash
131+
"SELECT COALESCE( MAX( id ), 0 ) FROM {$wpdb->sync_updates} WHERE room = %s",
132+
$room
135133
)
136134
);
137135

@@ -146,17 +144,17 @@ public function get_updates_after_cursor( string $room, int $cursor ): array {
146144
// Bounded by max_id to stay consistent with the snapshot window above.
147145
$this->room_update_counts[ $room ] = (int) $wpdb->get_var(
148146
$wpdb->prepare(
149-
"SELECT COUNT(*) FROM {$wpdb->sync_updates} WHERE room_hash = %s AND id <= %d",
150-
$room_hash,
147+
"SELECT COUNT(*) FROM {$wpdb->sync_updates} WHERE room = %s AND id <= %d",
148+
$room,
151149
$max_id
152150
)
153151
);
154152

155153
// Fetch updates after the cursor up to the snapshot boundary.
156154
$rows = $wpdb->get_results(
157155
$wpdb->prepare(
158-
"SELECT update_value FROM {$wpdb->sync_updates} WHERE room_hash = %s AND id > %d AND id <= %d ORDER BY id ASC",
159-
$room_hash,
156+
"SELECT update_value FROM {$wpdb->sync_updates} WHERE room = %s AND id > %d AND id <= %d ORDER BY id ASC",
157+
$room,
160158
$cursor,
161159
$max_id
162160
)
@@ -193,8 +191,8 @@ public function remove_updates_before_cursor( string $room, int $cursor ): bool
193191

194192
$result = $wpdb->query(
195193
$wpdb->prepare(
196-
"DELETE FROM {$wpdb->sync_updates} WHERE room_hash = %s AND id < %d",
197-
md5( $room ),
194+
"DELETE FROM {$wpdb->sync_updates} WHERE room = %s AND id < %d",
195+
$room,
198196
$cursor
199197
)
200198
);
@@ -216,6 +214,6 @@ public function remove_updates_before_cursor( string $room, int $cursor ): bool
216214
public function set_awareness_state( string $room, array $awareness ): bool {
217215
// Awareness is high-frequency, short-lived data (cursor positions, selections)
218216
// that doesn't need cursor-based history. Transients avoid row churn in the table.
219-
return set_transient( 'sync_awareness_' . md5( $room ), $awareness, MINUTE_IN_SECONDS );
217+
return set_transient( 'sync_awareness_' . $room, $awareness, MINUTE_IN_SECONDS );
220218
}
221219
}

src/wp-includes/rest-api.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ function create_initial_rest_routes() {
430430
$icons_controller->register_routes();
431431

432432
// Collaboration.
433-
if ( get_option( 'wp_enable_real_time_collaboration' ) && get_option( 'db_version' ) >= 61697 ) {
433+
if ( get_option( 'wp_enable_real_time_collaboration' ) && get_option( 'db_version' ) >= 61698 ) {
434434
$sync_storage = new WP_Sync_Table_Storage();
435435

436436
/**

src/wp-includes/version.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
*
2424
* @global int $wp_db_version
2525
*/
26-
$wp_db_version = 61697;
26+
$wp_db_version = 61698;
2727

2828
/**
2929
* Holds the TinyMCE version.

0 commit comments

Comments
 (0)