WP_HTTP_Polling_Sync_Server::get_updatesprivateWP 7.0.0

Gets sync updates for a specific client from a room after a given cursor.

Delegates cursor-based retrieval to the storage layer, then applies client-specific filtering and compaction logic.

Method of the class: WP_HTTP_Polling_Sync_Server{}

No Hooks.

Returns

Array{ . end_cursor: int, should_compact: bool, room: string, total_updates: int, updates: array<int, array{data: string, type: string}>, } Response data for this room.

Usage

// private - for code of main (parent) class only
$result = $this->get_updates( $room, $client_id, $cursor, $is_compactor ): array;
$room(string) (required)
Room identifier.
$client_id(int) (required)
Client identifier.
$cursor(int) (required)
Return updates after this cursor.
$is_compactor(true|false) (required)
True if this client is nominated to perform compaction.

Changelog

Since 7.0.0 Introduced.

WP_HTTP_Polling_Sync_Server::get_updates() code WP 7.0

private function get_updates( string $room, int $client_id, int $cursor, bool $is_compactor ): array {
	$updates_after_cursor = $this->storage->get_updates_after_cursor( $room, $cursor );
	$total_updates        = $this->storage->get_update_count( $room );

	// Filter out this client's updates, except compaction updates.
	$typed_updates = array();
	foreach ( $updates_after_cursor as $update ) {
		if ( $client_id === $update['client_id'] && self::UPDATE_TYPE_COMPACTION !== $update['type'] ) {
			continue;
		}

		$typed_updates[] = array(
			'data' => $update['data'],
			'type' => $update['type'],
		);
	}

	$should_compact = $is_compactor && $total_updates > self::COMPACTION_THRESHOLD;

	return array(
		'end_cursor'     => $this->storage->get_cursor( $room ),
		'room'           => $room,
		'should_compact' => $should_compact,
		'total_updates'  => $total_updates,
		'updates'        => $typed_updates,
	);
}