Skip to content

Allow disabling timestamp-based freshness checks by using negative TTL values #1940

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

ShyamGadde
Copy link
Contributor

Summary

Fixes #1914

Relevant technical choices

  • Modified OD_URL_Metric_Group_Collection constructor to accept negative freshness TTL values
  • Updated OD_URL_Metric_Group::is_complete() to skip timestamp checks when freshness TTL is negative
  • Updated the od_get_url_metric_freshness_ttl() function to allow negative values

Signed-off-by: Shyamsundar Gadde <[email protected]>
Signed-off-by: Shyamsundar Gadde <[email protected]>
Signed-off-by: Shyamsundar Gadde <[email protected]>
Signed-off-by: Shyamsundar Gadde <[email protected]>
Signed-off-by: Shyamsundar Gadde <[email protected]>
@ShyamGadde ShyamGadde added [Type] Enhancement A suggestion for improvement of an existing feature [Plugin] Optimization Detective Issues for the Optimization Detective plugin labels Mar 18, 2025
Copy link

codecov bot commented Mar 18, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 71.09%. Comparing base (3d03c16) to head (b5e1892).
Report is 8 commits behind head on trunk.

Additional details and impacted files
@@           Coverage Diff           @@
##            trunk    #1940   +/-   ##
=======================================
  Coverage   71.08%   71.09%           
=======================================
  Files          86       86           
  Lines        6969     6970    +1     
=======================================
+ Hits         4954     4955    +1     
  Misses       2015     2015           
Flag Coverage Δ
multisite 71.09% <100.00%> (+<0.01%) ⬆️
single 40.57% <40.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@@ -73,7 +73,7 @@ final class OD_URL_Metric_Group_Collection implements Countable, IteratorAggrega
* A freshness age of zero means a URL Metric will always be considered stale.
*
* @since 0.1.0
* @var int<0, max>
* @var int
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to use:

Suggested change
* @var int
* @var int<-1, max>

And then throughout here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed it in b5ef506.

}

return $freshness_ttl;
return (int) apply_filters( 'od_url_metric_freshness_ttl', WEEK_IN_SECONDS );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per above, this could be:

Suggested change
return (int) apply_filters( 'od_url_metric_freshness_ttl', WEEK_IN_SECONDS );
$ttl = (int) apply_filters( 'od_url_metric_freshness_ttl', WEEK_IN_SECONDS );
return max( -1, $ttl );

@ShyamGadde ShyamGadde marked this pull request as ready for review March 19, 2025 14:23
@ShyamGadde ShyamGadde requested a review from felixarntz as a code owner March 19, 2025 14:23
Copy link

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: ShyamGadde <[email protected]>
Co-authored-by: westonruter <[email protected]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@@ -434,7 +434,8 @@ export default async function detect( {
);
if (
! isNaN( previousVisitTime ) &&
( getCurrentTime() - previousVisitTime ) / 1000 < freshnessTTL
( freshnessTTL < 0 ||
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A key bit I realized was missing. Without this, URL Metrics will always attempt to be submitted again even.

Copy link
Member

@westonruter westonruter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@westonruter westonruter merged commit a3b0d7c into WordPress:trunk Mar 19, 2025
20 of 21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Plugin] Optimization Detective Issues for the Optimization Detective plugin [Type] Enhancement A suggestion for improvement of an existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Freshness TTL should be able to be disabled in favor of using ETag alone to determine whether URL Metric is stale
2 participants