Automattic\WooCommerce\Internal\PushNotifications\Services

StepLogQuery::take_page │ private static │ WC 1.0

Takes one page off the front of the rows, with the cursor for the next.

Timestamps are whole seconds and several steps of one notification share a second, so a page that stopped mid-second would skip or repeat rows on the next read. Where the limit falls inside a second the page carries every row of that second and may exceed the limit.

Метод класса: StepLogQuery{}

Хуков нет.

Возвращает

array{0: list<array>, 1: int|null}. The page, and the to for the next page or null.

Использование

$result = StepLogQuery::take_page( $rows, $limit, $has_more ): array;
$rows(массив) (обязательный)
Rows, newest first.
$limit(int) (обязательный)
Rows to return, before the whole-second rule.
$has_more(true|false) (обязательный)
Whether a reader stopped with older rows unread, which it only does once it holds the limit.

Код StepLogQuery::take_page() WC 11.3.0

private static function take_page( array $rows, int $limit, bool $has_more ): array {
	if ( count( $rows ) <= $limit && ! $has_more ) {
		return array( array_values( $rows ), null );
	}

	$rows     = array_values( $rows );
	$boundary = (int) $rows[ $limit - 1 ]['timestamp'];
	$page     = array_slice( $rows, 0, $limit );
	$next     = $limit;

	while ( isset( $rows[ $next ] ) && $boundary === (int) $rows[ $next ]['timestamp'] ) {
		$page[] = $rows[ $next ];
		++$next;
	}

	return array( $page, ( isset( $rows[ $next ] ) || $has_more ) ? $boundary - 1 : null );
}