Skip to content

Change default garbage collection TTL of od_url_metrics posts from 1 month to 3 months and add the filter to customize expiration #1950

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
merged 13 commits into from
Mar 27, 2025

Conversation

hbhalodia
Copy link
Contributor

@hbhalodia hbhalodia commented Mar 20, 2025

Summary

Fixes #1948

Relevant technical choices

  1. Registers the new filter named, od_url_metric_garbage_collection_ttl which filters the ttl time for gargage collection for url_metrics of the post and defaults to 3 months in seconds.
  2. Updates the documentation to add the usage of filter and default value.

Copy link

codecov bot commented Mar 20, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 72.27%. Comparing base (f751ae2) to head (14bddaf).
Report is 19 commits behind head on trunk.

Additional details and impacted files
@@            Coverage Diff             @@
##            trunk    #1950      +/-   ##
==========================================
+ Coverage   72.26%   72.27%   +0.01%     
==========================================
  Files          85       85              
  Lines        6958     6961       +3     
==========================================
+ Hits         5028     5031       +3     
  Misses       1930     1930              
Flag Coverage Δ
multisite 72.27% <100.00%> (+0.01%) ⬆️
single 40.69% <0.00%> (-0.02%) ⬇️

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.

@hbhalodia hbhalodia marked this pull request as ready for review March 21, 2025 06:02
@hbhalodia hbhalodia requested a review from felixarntz as a code owner March 21, 2025 06:02
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: hbhalodia <[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.

@hbhalodia hbhalodia requested a review from westonruter March 21, 2025 06:02
@hbhalodia
Copy link
Contributor Author

Hi @westonruter, This is now ready for the review.

Updates: Have updated the filter to only use the number, and also added the test case for the filter usage. Let me know if that filter usage test case should be in another function or any improvements in that.

Thank You,

@hbhalodia hbhalodia requested a review from westonruter March 24, 2025 05:12
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.

Just some tweaks.

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.

Thanks!

@westonruter westonruter added [Type] Enhancement A suggestion for improvement of an existing feature [Plugin] Optimization Detective Issues for the Optimization Detective plugin labels Mar 24, 2025
@westonruter westonruter changed the title Feat: Add the filter to change the default period of Garbage collection time window for URL Metrics posts Change default garbage collection of od_url_metrics posts from 1 month to 3 months and add the filter to customize TTL Mar 25, 2025
@westonruter westonruter changed the title Change default garbage collection of od_url_metrics posts from 1 month to 3 months and add the filter to customize TTL Change default garbage collection TTL of od_url_metrics posts from 1 month to 3 months and add the filter to customize expiration Mar 25, 2025
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.

A couple more copy tweaks

);

// Update timestamp to 6 months older.
$new_stale_timestamp_gmt = gmdate( 'Y-m-d H:i:s', time() - ( 6 * MONTH_IN_SECONDS * HOUR_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.

Oh, why is this multiplying MONTH_IN_SECONDS * HOUR_IN_SECONDS? Shouldn't this rather be rather one second longer than the expiration age of 6 * MONTH_IN_SECONDS?:

Suggested change
$new_stale_timestamp_gmt = gmdate( 'Y-m-d H:i:s', time() - ( 6 * MONTH_IN_SECONDS * HOUR_IN_SECONDS ) );
$new_stale_timestamp_gmt = gmdate( 'Y-m-d H:i:s', time() - ( 6 * MONTH_IN_SECONDS + 1 ) );

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Shouldn't this rather be rather one second longer than the expiration age of 6 * MONTH_IN_SECONDS

Yes it could be, but I thought to carry the same from the above where HOURS_IN_SECONDS was used.

I would change to + 1 rather. but not sure if it could make much difference IMO?

Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure I understand. What is MONTH_IN_SECONDS * HOUR_IN_SECONDS supposed to mean? That's like saying 3600 months of seconds. Multiplying seconds by other seconds doesn't make sense to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This makes sense, but I added because it was previously added here in the test -

$stale_timestamp_gmt = gmdate( 'Y-m-d H:i:s', strtotime( '-1 month' ) - HOUR_IN_SECONDS );
, I thought to carry forward the same.

So to make more consistent I have added that.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, but that is quite different. That's subtracting one unit of seconds from another unit of seconds, so the resulting unit is seconds. By multiplying two units of seconds together then you kinda get a strange unit: seconds².

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, but that is quite different. That's subtracting one unit of seconds from another unit of seconds, so the resulting unit is seconds. By multiplying two units of seconds together then you kinda get a strange unit: seconds².

Yep Gotcha!

@westonruter westonruter merged commit 80f8762 into WordPress:trunk Mar 27, 2025
19 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.

Garbage collection time window for URL Metrics posts could be increased and made customizable
2 participants