Skip to content

Commit f743e64

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

4 files changed

Lines changed: 10 additions & 10 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: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ public function get_updates_after_cursor( string $room, int $cursor ): array {
192192
/* Snapshot the current max ID and total row count in a single query. */
193193
$snapshot = $wpdb->get_row(
194194
$wpdb->prepare(
195-
"SELECT COALESCE( MAX( id ), 0 ) AS max_id, COUNT(*) AS total FROM {$wpdb->collaboration} WHERE room = %s AND type != 'awareness'",
195+
"SELECT COALESCE( MAX( collaboration_id ), 0 ) AS max_id, COUNT(*) AS total FROM {$wpdb->collaboration} WHERE room = %s AND type != 'awareness'",
196196
$room
197197
)
198198
);
@@ -223,7 +223,7 @@ public function get_updates_after_cursor( string $room, int $cursor ): array {
223223
/* Fetch updates after the cursor up to the snapshot boundary. */
224224
$rows = $wpdb->get_results(
225225
$wpdb->prepare(
226-
"SELECT data FROM {$wpdb->collaboration} WHERE room = %s AND type != 'awareness' AND id > %d AND id <= %d ORDER BY id ASC",
226+
"SELECT data FROM {$wpdb->collaboration} WHERE room = %s AND type != 'awareness' AND collaboration_id > %d AND collaboration_id <= %d ORDER BY collaboration_id ASC",
227227
$room,
228228
$cursor,
229229
$max_id
@@ -263,7 +263,7 @@ public function remove_updates_through_cursor( string $room, int $cursor ): bool
263263
// "delete all, re-add some" pattern.
264264
$result = $wpdb->query(
265265
$wpdb->prepare(
266-
"DELETE FROM {$wpdb->collaboration} WHERE room = %s AND type != 'awareness' AND id <= %d",
266+
"DELETE FROM {$wpdb->collaboration} WHERE room = %s AND type != 'awareness' AND collaboration_id <= %d",
267267
$room,
268268
$cursor
269269
)
@@ -316,7 +316,7 @@ public function set_awareness_state( string $room, string $client_id, array $sta
316316
/* Check if a row already exists. */
317317
$exists = $wpdb->get_row(
318318
$wpdb->prepare(
319-
"SELECT id, date_gmt FROM {$wpdb->collaboration} WHERE room = %s AND type = 'awareness' AND client_id = %s LIMIT 1",
319+
"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",
320320
$room,
321321
$client_id
322322
)
@@ -335,7 +335,7 @@ public function set_awareness_state( string $room, string $client_id, array $sta
335335
'data' => $data,
336336
'date_gmt' => $now,
337337
),
338-
array( 'id' => $exists->id )
338+
array( 'collaboration_id' => $exists->collaboration_id )
339339
);
340340
} else {
341341
$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
@@ -2986,7 +2986,7 @@ public function test_collaboration_cursor_ids_are_unique_and_ordered(): void {
29862986

29872987
$ids = $wpdb->get_col(
29882988
$wpdb->prepare(
2989-
"SELECT id FROM {$wpdb->collaboration} WHERE room = %s AND type != 'awareness' ORDER BY id ASC",
2989+
"SELECT collaboration_id FROM {$wpdb->collaboration} WHERE room = %s AND type != 'awareness' ORDER BY collaboration_id ASC",
29902990
$room
29912991
)
29922992
);

0 commit comments

Comments
 (0)