Skip to content

Commit c3fc522

Browse files
Prefix schema ID column with collaboration per other WP tables.
Co-Authored-By: westonruter <[email protected]>
1 parent 6963888 commit c3fc522

4 files changed

Lines changed: 11 additions & 11 deletions

File tree

src/wp-admin/includes/schema.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,16 +188,16 @@ function wp_get_db_schema( $scope = 'all', $blog_id = null ) {
188188
KEY type_status_author (post_type,post_status,post_author)
189189
) $charset_collate;
190190
CREATE TABLE $wpdb->collaboration (
191-
id bigint(20) unsigned NOT NULL auto_increment,
191+
collaboration_id bigint(20) unsigned NOT NULL auto_increment,
192192
room varchar($max_index_length) NOT NULL default '',
193193
type varchar(32) NOT NULL default '',
194194
client_id varchar(32) NOT NULL default '',
195195
user_id bigint(20) unsigned NOT NULL default '0',
196196
data longtext NOT NULL,
197197
date_gmt datetime NOT NULL default '0000-00-00 00:00:00',
198-
PRIMARY KEY (id),
198+
PRIMARY KEY (collaboration_id),
199199
KEY type_client_id (type,client_id),
200-
KEY room (room,id),
200+
KEY room (room,collaboration_id),
201201
KEY room_type_date (room,type,date_gmt),
202202
KEY date_gmt (date_gmt)
203203
) $charset_collate;\n";

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public function get_awareness_state( string $room, int $timeout = 30 ): array {
145145

146146
$rows = $wpdb->get_results(
147147
$wpdb->prepare(
148-
"SELECT client_id, user_id, date_gmt, data FROM {$wpdb->collaboration} WHERE room = %s AND type = 'awareness' AND date_gmt >= %s ORDER BY id ASC",
148+
"SELECT client_id, user_id, date_gmt, data FROM {$wpdb->collaboration} WHERE room = %s AND type = 'awareness' AND date_gmt >= %s ORDER BY collaboration_id ASC",
149149
$room,
150150
$cutoff_mysql
151151
)
@@ -231,7 +231,7 @@ public function get_updates_after_cursor( string $room, int $cursor ): array {
231231
/* Snapshot the current max ID and total row count in a single query. */
232232
$snapshot = $wpdb->get_row(
233233
$wpdb->prepare(
234-
"SELECT COALESCE( MAX( id ), 0 ) AS max_id, COUNT(*) AS total FROM {$wpdb->collaboration} WHERE room = %s AND type != 'awareness'",
234+
"SELECT COALESCE( MAX( collaboration_id ), 0 ) AS max_id, COUNT(*) AS total FROM {$wpdb->collaboration} WHERE room = %s AND type != 'awareness'",
235235
$room
236236
)
237237
);
@@ -262,7 +262,7 @@ public function get_updates_after_cursor( string $room, int $cursor ): array {
262262
/* Fetch updates after the cursor up to the snapshot boundary. */
263263
$rows = $wpdb->get_results(
264264
$wpdb->prepare(
265-
"SELECT data FROM {$wpdb->collaboration} WHERE room = %s AND type != 'awareness' AND id > %d AND id <= %d ORDER BY id ASC",
265+
"SELECT data FROM {$wpdb->collaboration} WHERE room = %s AND type != 'awareness' AND collaboration_id > %d AND collaboration_id <= %d ORDER BY collaboration_id ASC",
266266
$room,
267267
$cursor,
268268
$max_id
@@ -302,7 +302,7 @@ public function remove_updates_through_cursor( string $room, int $cursor ): bool
302302
// "delete all, re-add some" pattern.
303303
$result = $wpdb->query(
304304
$wpdb->prepare(
305-
"DELETE FROM {$wpdb->collaboration} WHERE room = %s AND type != 'awareness' AND id <= %d",
305+
"DELETE FROM {$wpdb->collaboration} WHERE room = %s AND type != 'awareness' AND collaboration_id <= %d",
306306
$room,
307307
$cursor
308308
)
@@ -413,7 +413,7 @@ public function set_awareness_state( string $room, string $client_id, array $sta
413413
*/
414414
$exists = $wpdb->get_row(
415415
$wpdb->prepare(
416-
"SELECT id, date_gmt, data FROM {$wpdb->collaboration} WHERE room = %s AND type = 'awareness' AND client_id = %s ORDER BY id DESC LIMIT 1",
416+
"SELECT collaboration_id, date_gmt, data FROM {$wpdb->collaboration} WHERE room = %s AND type = 'awareness' AND client_id = %s ORDER BY collaboration_id DESC LIMIT 1",
417417
$room,
418418
$client_id
419419
)
@@ -432,7 +432,7 @@ public function set_awareness_state( string $room, string $client_id, array $sta
432432
'data' => $data,
433433
'date_gmt' => $now_mysql,
434434
),
435-
array( 'id' => $exists->id )
435+
array( 'collaboration_id' => $exists->collaboration_id )
436436
);
437437
} else {
438438
$result = $wpdb->insert(

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 = 61842;
26+
$wp_db_version = 61844;
2727

2828
/**
2929
* Holds the TinyMCE version.

tests/phpunit/tests/rest-api/rest-collaboration-server.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3003,7 +3003,7 @@ public function test_collaboration_cursor_ids_are_unique_and_ordered(): void {
30033003

30043004
$ids = $wpdb->get_col(
30053005
$wpdb->prepare(
3006-
"SELECT id FROM {$wpdb->collaboration} WHERE room = %s AND type != 'awareness' ORDER BY id ASC",
3006+
"SELECT collaboration_id FROM {$wpdb->collaboration} WHERE room = %s AND type != 'awareness' ORDER BY collaboration_id ASC",
30073007
$room
30083008
)
30093009
);

0 commit comments

Comments
 (0)