Skip to content

Commit 4bf2584

Browse files
committed
Collaboration: Rename update_value column to data
Rename the `update_value` column to `data` in the collaboration table schema, storage class, and tests per feedback in comment:73. The shorter name is consistent with WordPress meta tables and avoids confusion with the `update_value()` method in `WP_REST_Meta_Fields`. See #64696.
1 parent 09d0b86 commit 4bf2584

2 files changed

Lines changed: 28 additions & 28 deletions

File tree

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

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function add_update( string $room, $update ): bool {
6262
'room' => $room,
6363
'type' => $update['type'] ?? '',
6464
'client_id' => $update['client_id'] ?? '',
65-
'update_value' => wp_json_encode( $update ),
65+
'data' => wp_json_encode( $update ),
6666
'date_gmt' => gmdate( 'Y-m-d H:i:s' ),
6767
),
6868
array( '%s', '%s', '%s', '%s', '%s' )
@@ -107,7 +107,7 @@ public function get_awareness_state( string $room, int $timeout = 30 ): array {
107107

108108
$rows = $wpdb->get_results(
109109
$wpdb->prepare(
110-
"SELECT client_id, user_id, update_value FROM {$wpdb->collaboration} WHERE room = %s AND type = 'awareness' AND date_gmt >= %s",
110+
"SELECT client_id, user_id, data FROM {$wpdb->collaboration} WHERE room = %s AND type = 'awareness' AND date_gmt >= %s",
111111
$room,
112112
$cutoff
113113
)
@@ -119,7 +119,7 @@ public function get_awareness_state( string $room, int $timeout = 30 ): array {
119119

120120
$entries = array();
121121
foreach ( $rows as $row ) {
122-
$decoded = json_decode( $row->update_value, true );
122+
$decoded = json_decode( $row->data, true );
123123
if ( is_array( $decoded ) ) {
124124
$entries[] = array(
125125
'client_id' => $row->client_id,
@@ -215,7 +215,7 @@ public function get_updates_after_cursor( string $room, int $cursor ): array {
215215
// Fetch updates after the cursor up to the snapshot boundary.
216216
$rows = $wpdb->get_results(
217217
$wpdb->prepare(
218-
"SELECT update_value FROM {$wpdb->collaboration} WHERE room = %s AND type != 'awareness' AND id > %d AND id <= %d ORDER BY id ASC",
218+
"SELECT data FROM {$wpdb->collaboration} WHERE room = %s AND type != 'awareness' AND id > %d AND id <= %d ORDER BY id ASC",
219219
$room,
220220
$cursor,
221221
$max_id
@@ -228,7 +228,7 @@ public function get_updates_after_cursor( string $room, int $cursor ): array {
228228

229229
$updates = array();
230230
foreach ( $rows as $row ) {
231-
$decoded = json_decode( $row->update_value, true );
231+
$decoded = json_decode( $row->data, true );
232232
if ( is_array( $decoded ) ) {
233233
$updates[] = $decoded;
234234
}
@@ -293,16 +293,16 @@ public function remove_updates_before_cursor( string $room, int $cursor ): bool
293293
public function set_awareness_state( string $room, string $client_id, array $state, int $user_id ): bool {
294294
global $wpdb;
295295

296-
$update_value = wp_json_encode( $state );
297-
$now = gmdate( 'Y-m-d H:i:s' );
296+
$data = wp_json_encode( $state );
297+
$now = gmdate( 'Y-m-d H:i:s' );
298298

299299
// Try UPDATE first.
300300
$updated = $wpdb->update(
301301
$wpdb->collaboration,
302302
array(
303-
'user_id' => $user_id,
304-
'update_value' => $update_value,
305-
'date_gmt' => $now,
303+
'user_id' => $user_id,
304+
'data' => $data,
305+
'date_gmt' => $now,
306306
),
307307
array(
308308
'room' => $room,
@@ -316,12 +316,12 @@ public function set_awareness_state( string $room, string $client_id, array $sta
316316
$result = $wpdb->insert(
317317
$wpdb->collaboration,
318318
array(
319-
'room' => $room,
320-
'type' => 'awareness',
321-
'client_id' => $client_id,
322-
'user_id' => $user_id,
323-
'update_value' => $update_value,
324-
'date_gmt' => $now,
319+
'room' => $room,
320+
'type' => 'awareness',
321+
'client_id' => $client_id,
322+
'user_id' => $user_id,
323+
'data' => $data,
324+
'date_gmt' => $now,
325325
)
326326
);
327327

@@ -339,7 +339,7 @@ public function set_awareness_state( string $room, string $client_id, array $sta
339339
$cached = wp_cache_get( $cache_key, 'collaboration' );
340340

341341
if ( false !== $cached ) {
342-
$normalized_state = json_decode( $update_value, true );
342+
$normalized_state = json_decode( $data, true );
343343
$found = false;
344344

345345
foreach ( $cached as $i => $entry ) {

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,7 +1157,7 @@ public function test_collaboration_compaction_reduces_total_updates(): void {
11571157
* Inserts a row directly into the collaboration table with a given age.
11581158
*
11591159
* @param positive-int $age_in_seconds How old the row should be.
1160-
* @param string $label A label stored in the update_value for identification.
1160+
* @param string $label A label stored in the data column for identification.
11611161
*/
11621162
private function insert_collaboration_row( int $age_in_seconds, string $label = 'test' ): void {
11631163
global $wpdb;
@@ -1168,7 +1168,7 @@ private function insert_collaboration_row( int $age_in_seconds, string $label =
11681168
'room' => $this->get_post_room(),
11691169
'type' => 'update',
11701170
'client_id' => '1',
1171-
'update_value' => wp_json_encode(
1171+
'data' => wp_json_encode(
11721172
array(
11731173
'type' => 'update',
11741174
'data' => $label,
@@ -1236,7 +1236,7 @@ public function test_cron_cleanup_boundary_at_exactly_seven_days(): void {
12361236
wp_delete_old_collaboration_data();
12371237

12381238
global $wpdb;
1239-
$remaining = $wpdb->get_col( "SELECT update_value FROM {$wpdb->collaboration}" );
1239+
$remaining = $wpdb->get_col( "SELECT data FROM {$wpdb->collaboration}" );
12401240

12411241
$this->assertCount( 1, $remaining, 'Only the row within the 7-day window should remain.' );
12421242
$this->assertStringContainsString( 'just-inside', $remaining[0], 'The surviving row should be the one inside the window.' );
@@ -1289,7 +1289,7 @@ public function test_collaboration_routes_not_registered_when_db_version_is_old(
12891289
$server = rest_get_server();
12901290
$routes = $server->get_routes();
12911291

1292-
$this->assertArrayNotHasKey( '/wp-collaboration/v1/updates', $routes, 'Collaboration routes should not be registered when db_version is below 61840.' );
1292+
$this->assertArrayNotHasKey( '/wp-collaboration/v1/updates', $routes, 'Collaboration routes should not be registered when db_version is below 61841.' );
12931293

12941294
// Reset again so subsequent tests get a server with the correct db_version.
12951295
$GLOBALS['wp_rest_server'] = null;
@@ -1445,7 +1445,7 @@ public function test_collaboration_expired_awareness_rows_cleaned_up(): void {
14451445
'type' => 'awareness',
14461446
'client_id' => '99',
14471447
'user_id' => self::$editor_id,
1448-
'update_value' => wp_json_encode( array( 'cursor' => 'stale' ) ),
1448+
'data' => wp_json_encode( array( 'cursor' => 'stale' ) ),
14491449
'date_gmt' => gmdate( 'Y-m-d H:i:s', time() - 120 ),
14501450
),
14511451
array( '%s', '%s', '%s', '%d', '%s', '%s' )
@@ -1501,7 +1501,7 @@ public function test_cron_cleanup_deletes_expired_awareness_rows(): void {
15011501
'type' => 'awareness',
15021502
'client_id' => '42',
15031503
'user_id' => self::$editor_id,
1504-
'update_value' => wp_json_encode( array( 'cursor' => 'old' ) ),
1504+
'data' => wp_json_encode( array( 'cursor' => 'old' ) ),
15051505
'date_gmt' => gmdate( 'Y-m-d H:i:s', time() - 120 ),
15061506
),
15071507
array( '%s', '%s', '%s', '%d', '%s', '%s' )
@@ -1521,7 +1521,7 @@ public function test_cron_cleanup_deletes_expired_awareness_rows(): void {
15211521

15221522
/**
15231523
* Verifies that user_id is stored as a dedicated column,
1524-
* not embedded inside the update_value JSON blob.
1524+
* not embedded inside the data JSON blob.
15251525
*
15261526
* @ticket 64696
15271527
*/
@@ -1539,20 +1539,20 @@ public function test_collaboration_awareness_user_id_round_trip() {
15391539
// Query the collaboration table directly for the awareness row.
15401540
$row = $wpdb->get_row(
15411541
$wpdb->prepare(
1542-
"SELECT user_id, update_value FROM {$wpdb->collaboration} WHERE room = %s AND type = 'awareness' AND client_id = %s",
1542+
"SELECT user_id, data FROM {$wpdb->collaboration} WHERE room = %s AND type = 'awareness' AND client_id = %s",
15431543
$room,
15441544
'1'
15451545
)
15461546
);
15471547

15481548
$this->assertNotNull( $row, 'Awareness row should exist.' );
15491549
$this->assertSame( self::$editor_id, (int) $row->user_id, 'user_id column should match the editor.' );
1550-
$this->assertStringNotContainsString( 'user_id', $row->update_value, 'update_value should not contain user_id.' );
1550+
$this->assertStringNotContainsString( 'user_id', $row->data, 'data column should not contain user_id.' );
15511551
}
15521552

15531553
/**
15541554
* Verifies that the is_array() guard in get_awareness_state() skips
1555-
* rows where update_value contains valid JSON that is not an array.
1555+
* rows where the data column contains valid JSON that is not an array.
15561556
*
15571557
* @ticket 64696
15581558
*/
@@ -1571,7 +1571,7 @@ public function test_collaboration_awareness_non_array_json_ignored() {
15711571
'type' => 'awareness',
15721572
'client_id' => '99',
15731573
'user_id' => self::$editor_id,
1574-
'update_value' => '"hello"',
1574+
'data' => '"hello"',
15751575
'date_gmt' => gmdate( 'Y-m-d H:i:s' ),
15761576
),
15771577
array( '%s', '%s', '%s', '%d', '%s', '%s' )

0 commit comments

Comments
 (0)