Automattic\WooCommerce\Internal\PushNotifications\DataStores

StepLogFileReader::keep_newest │ private static │ WC 1.0

Keeps the newest rows and whatever shares the oldest kept second, so a trim can never cut a second in half.

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

Хуков нет.

Возвращает

array.

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

$result = StepLogFileReader::keep_newest( $rows, $limit ): array;
$rows(массив) (обязательный)
The rows held so far.
$limit(int) (обязательный)
The fewest rows to keep.

Код StepLogFileReader::keep_newest() WC 11.3.0

private static function keep_newest( array $rows, int $limit ): array {
	if ( PHP_INT_MAX === $limit || count( $rows ) <= $limit ) {
		return $rows;
	}

	usort( $rows, fn( array $a, array $b ) => $b['timestamp'] <=> $a['timestamp'] );

	$boundary = $rows[ $limit - 1 ]['timestamp'];

	return array_values( array_filter( $rows, fn( array $row ) => $row['timestamp'] >= $boundary ) );
}