Skip to content

Commit

Permalink
Rename od_compute_current_etag() to od_get_current_etag() for parity …
Browse files Browse the repository at this point in the history
…with od_get_url_metrics_slug()
  • Loading branch information
westonruter committed Dec 1, 2024
1 parent bcc34c9 commit 4f0ac4c
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 24 deletions.
2 changes: 1 addition & 1 deletion plugins/optimization-detective/optimization.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ function od_optimize_template_output_buffer( string $buffer ): string {
*/
do_action( 'od_register_tag_visitors', $tag_visitor_registry );

$current_etag = od_compute_current_etag( $tag_visitor_registry );
$current_etag = od_get_current_etag( $tag_visitor_registry );
$group_collection = new OD_URL_Metric_Group_Collection(
$post instanceof WP_Post ? OD_URL_Metrics_Post_Type::get_url_metrics_from_post( $post ) : array(),
$current_etag,
Expand Down
4 changes: 2 additions & 2 deletions plugins/optimization-detective/storage/data.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ function od_get_url_metrics_slug( array $query_vars ): string {
}

/**
* Computes the current ETag for URL Metrics.
* Gets the current ETag for URL Metrics.
*
* The ETag is a hash based on the IDs of the registered tag visitors
* in the current environment. It is used for marking the URL Metrics as stale
Expand All @@ -153,7 +153,7 @@ function od_get_url_metrics_slug( array $query_vars ): string {
* @param OD_Tag_Visitor_Registry $tag_visitor_registry Tag visitor registry.
* @return non-empty-string Current ETag.
*/
function od_compute_current_etag( OD_Tag_Visitor_Registry $tag_visitor_registry ): string {
function od_get_current_etag( OD_Tag_Visitor_Registry $tag_visitor_registry ): string {
$data = array(
'tag_visitors' => array_keys( iterator_to_array( $tag_visitor_registry ) ),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ function ( OD_URL_Metric_Store_Request_Context $context ) use ( &$stored_context
*/
public function data_provider_invalid_params(): array {
$valid_element = $this->get_valid_params()['elements'][0];
$current_etag = od_compute_current_etag( new OD_Tag_Visitor_Registry() );
$current_etag = od_get_current_etag( new OD_Tag_Visitor_Registry() );

return array_map(
function ( $params ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
'isLCP' => true,
),
),
od_compute_current_etag( $tag_visitor_registry )
od_get_current_etag( $tag_visitor_registry )
);
},
'buffer' => '
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
$tag_visitor_registry->register( 'img', static function (): void {} );
$tag_visitor_registry->register( 'video', static function (): void {} );

$test_case->populate_url_metrics( $elements, od_compute_current_etag( $tag_visitor_registry ), false );
$test_case->populate_url_metrics( $elements, od_get_current_etag( $tag_visitor_registry ), false );
},
'buffer' => '
<html lang="en">
Expand Down
2 changes: 1 addition & 1 deletion plugins/optimization-detective/tests/test-cases/video.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
'isLCP' => true,
),
),
od_compute_current_etag( $tag_visitor_registry ),
od_get_current_etag( $tag_visitor_registry ),
false
);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ static function ( array $schema ): array {
$this->assertInstanceOf( OD_Element::class, $element );
$this->assertSame( $url_metric, $element->get_url_metric() );
$this->assertNull( $element->get_url_metric_group() );
$current_etag = od_compute_current_etag( new OD_Tag_Visitor_Registry() );
$current_etag = od_get_current_etag( new OD_Tag_Visitor_Registry() );
$collection = new OD_URL_Metric_Group_Collection( array( $url_metric ), $current_etag, array(), 1, DAY_IN_SECONDS );
$collection->add_url_metric( $url_metric );
$this->assertSame( iterator_to_array( $collection )[0], $element->get_url_metric_group() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Test_OD_URL_Metric_Group_Collection extends WP_UnitTestCase {
* @return array<string, mixed> Data.
*/
public function data_provider_test_construction(): array {
$current_etag = od_compute_current_etag( new OD_Tag_Visitor_Registry() );
$current_etag = od_get_current_etag( new OD_Tag_Visitor_Registry() );

return array(
'no_breakpoints_ok' => array(
Expand Down Expand Up @@ -196,7 +196,7 @@ public function data_provider_sample_size_and_breakpoints(): array {
* @dataProvider data_provider_sample_size_and_breakpoints
*/
public function test_add_url_metric( int $sample_size, array $breakpoints, array $viewport_widths, array $expected_counts ): void {
$current_etag = od_compute_current_etag( new OD_Tag_Visitor_Registry() );
$current_etag = od_get_current_etag( new OD_Tag_Visitor_Registry() );
$group_collection = new OD_URL_Metric_Group_Collection( array(), $current_etag, $breakpoints, $sample_size, HOUR_IN_SECONDS );

// Over-populate the sample size for the breakpoints by a dozen.
Expand Down Expand Up @@ -225,7 +225,7 @@ public function test_add_url_metric( int $sample_size, array $breakpoints, array
* @covers ::add_url_metric
*/
public function test_adding_pushes_out_old_metrics(): void {
$current_etag = od_compute_current_etag( new OD_Tag_Visitor_Registry() );
$current_etag = od_get_current_etag( new OD_Tag_Visitor_Registry() );
$sample_size = 3;
$breakpoints = array( 400, 600 );
$group_collection = new OD_URL_Metric_Group_Collection( array(), $current_etag, $breakpoints, $sample_size, HOUR_IN_SECONDS );
Expand Down Expand Up @@ -349,7 +349,7 @@ function ( $viewport_width ) {
$viewport_widths
);

$current_etag = od_compute_current_etag( new OD_Tag_Visitor_Registry() );
$current_etag = od_get_current_etag( new OD_Tag_Visitor_Registry() );
$group_collection = new OD_URL_Metric_Group_Collection( $url_metrics, $current_etag, $breakpoints, 3, HOUR_IN_SECONDS );

$this->assertCount(
Expand Down Expand Up @@ -514,7 +514,7 @@ public function data_provider_test_get_group_for_viewport_width(): array {
* @param array<int, bool> $expected_is_group_complete Expected is group complete.
*/
public function test_get_group_for_viewport_width( array $url_metrics, float $current_time, array $breakpoints, int $sample_size, int $freshness_ttl, array $expected_return, array $expected_is_group_complete ): void {
$current_etag = od_compute_current_etag( new OD_Tag_Visitor_Registry() );
$current_etag = od_get_current_etag( new OD_Tag_Visitor_Registry() );
$group_collection = new OD_URL_Metric_Group_Collection( $url_metrics, $current_etag, $breakpoints, $sample_size, $freshness_ttl );
$this->assertSame(
$expected_return,
Expand Down Expand Up @@ -547,7 +547,7 @@ static function ( OD_URL_Metric_Group $group ): array {
public function test_is_every_group_populated(): void {
$breakpoints = array( 480, 800 );
$sample_size = 3;
$current_etag = od_compute_current_etag( new OD_Tag_Visitor_Registry() );
$current_etag = od_get_current_etag( new OD_Tag_Visitor_Registry() );
$group_collection = new OD_URL_Metric_Group_Collection(
array(),
$current_etag,
Expand Down Expand Up @@ -602,7 +602,7 @@ public function test_get_groups_by_lcp_element(): void {

$breakpoints = array( 480, 800 );
$sample_size = 3;
$current_etag = od_compute_current_etag( new OD_Tag_Visitor_Registry() );
$current_etag = od_get_current_etag( new OD_Tag_Visitor_Registry() );
$group_collection = new OD_URL_Metric_Group_Collection(
array(
// Group 1: 0-480 viewport widths.
Expand Down Expand Up @@ -645,7 +645,7 @@ public function test_get_groups_by_lcp_element(): void {
public function test_get_common_lcp_element(): void {
$breakpoints = array( 480, 800 );
$sample_size = 3;
$current_etag = od_compute_current_etag( new OD_Tag_Visitor_Registry() );
$current_etag = od_get_current_etag( new OD_Tag_Visitor_Registry() );
$group_collection = new OD_URL_Metric_Group_Collection(
array(),
$current_etag,
Expand Down Expand Up @@ -759,7 +759,7 @@ public function data_provider_element_max_intersection_ratios(): array {
* @param array<string, float> $expected Expected.
*/
public function test_get_all_element_max_intersection_ratios( array $url_metrics, array $expected ): void {
$current_etag = od_compute_current_etag( new OD_Tag_Visitor_Registry() );
$current_etag = od_get_current_etag( new OD_Tag_Visitor_Registry() );
$breakpoints = array( 480, 600, 782 );
$sample_size = 3;
$group_collection = new OD_URL_Metric_Group_Collection( $url_metrics, $current_etag, $breakpoints, $sample_size, 0 );
Expand Down Expand Up @@ -937,7 +937,7 @@ public function data_provider_get_all_elements_positioned_in_any_initial_viewpor
* @param array<string, bool> $expected Expected.
*/
public function test_get_all_elements_positioned_in_any_initial_viewport( array $url_metrics, array $expected ): void {
$current_etag = od_compute_current_etag( new OD_Tag_Visitor_Registry() );
$current_etag = od_get_current_etag( new OD_Tag_Visitor_Registry() );
$breakpoints = array( 480, 600, 782 );
$sample_size = 3;
$group_collection = new OD_URL_Metric_Group_Collection( $url_metrics, $current_etag, $breakpoints, $sample_size, 0 );
Expand All @@ -964,7 +964,7 @@ public function test_get_flattened_url_metrics(): void {

$group_collection = new OD_URL_Metric_Group_Collection(
$url_metrics,
od_compute_current_etag( new OD_Tag_Visitor_Registry() ),
od_get_current_etag( new OD_Tag_Visitor_Registry() ),
array( 500, 700 ),
3,
HOUR_IN_SECONDS
Expand Down Expand Up @@ -992,7 +992,7 @@ public function test_json_serialize(): void {

$group_collection = new OD_URL_Metric_Group_Collection(
$url_metrics,
od_compute_current_etag( new OD_Tag_Visitor_Registry() ),
od_get_current_etag( new OD_Tag_Visitor_Registry() ),
array( 500, 700 ),
3,
HOUR_IN_SECONDS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ public function data_provider_test_get_lcp_element(): array {
* @param array<int, string> $expected_lcp_element_xpaths Expected XPaths.
*/
public function test_get_lcp_element( array $breakpoints, array $url_metrics, array $expected_lcp_element_xpaths ): void {
$current_etag = od_compute_current_etag( new OD_Tag_Visitor_Registry() );
$current_etag = od_get_current_etag( new OD_Tag_Visitor_Registry() );
$group_collection = new OD_URL_Metric_Group_Collection( $url_metrics, $current_etag, $breakpoints, 10, HOUR_IN_SECONDS );

$lcp_element_xpaths_by_minimum_viewport_widths = array();
Expand Down
2 changes: 1 addition & 1 deletion plugins/optimization-detective/tests/test-detection.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ static function ( array $urls ): array {
public function test_od_get_detection_script_returns_script( Closure $set_up, array $expected_exports ): void {
$set_up();
$slug = od_get_url_metrics_slug( array( 'p' => '1' ) );
$current_etag = od_compute_current_etag( new OD_Tag_Visitor_Registry() );
$current_etag = od_get_current_etag( new OD_Tag_Visitor_Registry() );

$breakpoints = array( 480, 600, 782 );
$group_collection = new OD_URL_Metric_Group_Collection( array(), $current_etag, $breakpoints, 3, HOUR_IN_SECONDS );
Expand Down
4 changes: 2 additions & 2 deletions tests/class-optimization-detective-test-helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ trait Optimization_Detective_Test_Helpers {
*/
public function populate_url_metrics( array $elements, ?string $etag, bool $complete = true ): void {
$slug = od_get_url_metrics_slug( od_get_normalized_query_vars() );
$etag = $etag ?? od_compute_current_etag( new OD_Tag_Visitor_Registry() );
$etag = $etag ?? od_get_current_etag( new OD_Tag_Visitor_Registry() );
$sample_size = $complete ? od_get_url_metrics_breakpoint_sample_size() : 1;
foreach ( array_merge( od_get_breakpoint_max_widths(), array( 1000 ) ) as $viewport_width ) {
for ( $i = 0; $i < $sample_size; $i++ ) {
Expand Down Expand Up @@ -81,7 +81,7 @@ public function get_sample_dom_rect(): array {
public function get_sample_url_metric( array $params ): OD_URL_Metric {
$params = array_merge(
array(
'etag' => od_compute_current_etag( new OD_Tag_Visitor_Registry() ),
'etag' => od_get_current_etag( new OD_Tag_Visitor_Registry() ),
'url' => home_url( '/' ),
'viewport_width' => 480,
'elements' => array(),
Expand Down

0 comments on commit 4f0ac4c

Please sign in to comment.