Skip to content

Commit 60e520f

Browse files
committed
Allow granularity to be filtered.
1 parent 2c37f0c commit 60e520f

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/wp-includes/collaboration/class-wp-http-polling-sync-server.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,12 +355,25 @@ private function process_awareness_update( string $room, int $client_id, ?array
355355
$updated_awareness[] = $entry;
356356
}
357357

358+
/**
359+
* Filters granularity used for rounding up a client's awareness timestamp.
360+
*
361+
* Use to modify the granularity used when recording the latest time a client update their
362+
* awareness state. This allows implementations to increase or reduce the granularity
363+
* of awareness updates which can help reduce server load.
364+
*
365+
* @since 7.0.0
366+
*
367+
* @param int $granularity Granularity in seconds. Default 10.
368+
*/
369+
$granularity = (int) apply_filters( 'wp_sync_awareness_timestamp_granularity', 10 );
370+
358371
// Add this client's awareness state.
359372
if ( null !== $awareness_update ) {
360373
$updated_awareness[] = array(
361374
'client_id' => $client_id,
362375
'state' => $awareness_update,
363-
'updated_at' => ceil( time() / 10 ) * 10, // Round up to nearest 10 seconds to reduce database churn.
376+
'updated_at' => ceil( time() / $granularity ) * $granularity, // Round up to nearest granularity to reduce database churn.
364377
'wp_user_id' => get_current_user_id(),
365378
);
366379
}

0 commit comments

Comments
 (0)