Feature Description
This comes out of #1913 where my original solution was to fix test_get_lcp_element_when_group_half_stale was to provide a freshness TTL of -1 to disable it from consideration:
diff --git a/plugins/optimization-detective/tests/test-class-od-url-metrics-group.php b/plugins/optimization-detective/tests/test-class-od-url-metrics-group.php
index 209bb2b26..f1bd26548 100644
--- a/plugins/optimization-detective/tests/test-class-od-url-metrics-group.php
+++ b/plugins/optimization-detective/tests/test-class-od-url-metrics-group.php
@@ -469,7 +469,7 @@ class Test_OD_URL_Metric_Group extends WP_UnitTestCase {
$current_etag,
array( 480, 600, 782 ),
3,
- WEEK_IN_SECONDS
+ -1
);
$this->assertFalse( $collection->is_every_group_complete() );
This, however, fails because the constructor requires a positive integer:
|
* @phpstan-param int<0, max> $freshness_ttl |
|
// Set freshness TTL. |
|
if ( $freshness_ttl < 0 ) { |
|
throw new InvalidArgumentException( |
|
esc_html( |
|
sprintf( |
|
/* translators: %d is the invalid sample size */ |
|
__( 'Freshness TTL must be at least zero, but provided: %d', 'optimization-detective' ), |
|
$freshness_ttl |
|
) |
|
) |
|
); |
|
} |
Nevertheless, now that there is an ETag which is taken into account for considering whether a URL Metric is fresh (#1466), it would make sense to provide an option for a site to disregard the "freshness TTL" altogether when determining whether a URL Metric is stale:
|
// The URL Metric is too old to be fresh. |
|
if ( $current_time > $url_metric->get_timestamp() + $this->freshness_ttl ) { |
|
return false; |
|
} |
In other words, it should be possible for a site to do this:
add_filter( 'od_url_metric_freshness_ttl', function () { return -1; } );
But this is currently also blocked from being allowed:
|
$freshness_ttl = (int) apply_filters( 'od_url_metric_freshness_ttl', WEEK_IN_SECONDS ); |
|
|
|
if ( $freshness_ttl < 0 ) { |
|
_doing_it_wrong( |
|
__FUNCTION__, |
|
esc_html( |
|
sprintf( |
|
/* translators: %s is the TTL freshness */ |
|
__( 'Freshness TTL must be at least zero, but saw "%s".', 'optimization-detective' ), |
|
$freshness_ttl |
|
) |
|
), |
|
'' |
|
); |
|
$freshness_ttl = 0; |
|
} |
Allowing the freshness TTL to be disabled will allow URL Metrics to remain fresh indefinitely as long as the ETags do not change, that is, if the state of the site does not change.
Feature Description
This comes out of #1913 where my original solution was to fix
test_get_lcp_element_when_group_half_stalewas to provide a freshness TTL of -1 to disable it from consideration:This, however, fails because the constructor requires a positive integer:
performance/plugins/optimization-detective/class-od-url-metric-group-collection.php
Line 107 in 1a7f906
performance/plugins/optimization-detective/class-od-url-metric-group-collection.php
Lines 170 to 181 in 1a7f906
Nevertheless, now that there is an ETag which is taken into account for considering whether a URL Metric is fresh (#1466), it would make sense to provide an option for a site to disregard the "freshness TTL" altogether when determining whether a URL Metric is stale:
performance/plugins/optimization-detective/class-od-url-metric-group.php
Lines 302 to 305 in 1a7f906
In other words, it should be possible for a site to do this:
But this is currently also blocked from being allowed:
performance/plugins/optimization-detective/storage/data.php
Lines 36 to 51 in 1a7f906
Allowing the freshness TTL to be disabled will allow URL Metrics to remain fresh indefinitely as long as the ETags do not change, that is, if the state of the site does not change.