Skip to content

Commit d6dabe7

Browse files
committed
Reduce granuality to 10seconds, introduce filter.
1 parent e1e6a88 commit d6dabe7

1 file changed

Lines changed: 21 additions & 5 deletions

File tree

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

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -322,12 +322,28 @@ public function set_awareness_state( string $room, string $client_id, array $sta
322322

323323
wp_recursive_ksort( $state );
324324

325-
/*
326-
* Bucket the timestamp to 5-second intervals so most polls
327-
* short-circuit without a database write. Ceil is used instead
328-
* of floor to prevent the awareness timeout from being hit early.
325+
/**
326+
* Filters granularity used for rounding up a client's awareness timestamp.
327+
*
328+
* Modifies the granularity used when recording the latest time a client updates their
329+
* awareness state. This allows implementations to increase or reduce the granularity
330+
* of awareness updates for the desired balance of real-time updates and server load.
331+
*
332+
* The default database granularity of 10 seconds limits the number of writes to the
333+
* database as WordPress only makes the database call if the transient has changed.
334+
* Increasing the granularity by lowering this number will increase the number of
335+
* database writes.
336+
*
337+
* @since 7.0.0
338+
*
339+
* @param int $granularity Granularity in seconds. Default 10.
329340
*/
330-
$now_timestamp = (int) ceil( time() / 5 ) * 5;
341+
$granularity = absint( apply_filters( 'wp_sync_awareness_timestamp_granularity', 10 ) );
342+
if ( 0 === $granularity ) {
343+
$granularity = 1;
344+
}
345+
346+
$now_timestamp = (int) ceil( time() / $granularity ) * $granularity;
331347
$now_mysql = gmdate( 'Y-m-d H:i:s', $now_timestamp );
332348

333349
if ( wp_using_ext_object_cache() ) {

0 commit comments

Comments
 (0)