performance icon indicating copy to clipboard operation
performance copied to clipboard

Improve query var normalization

Open westonruter opened this issue 9 months ago • 1 comments

I realized that the current default order of query vars being used prior to generating the slug is not accounting for the fact that additional query vars can be registered on the fly via $wp->set_query_var( $key, $value ). So this ensures the keys are all in ascending order.

This will change the order of query vars used in the computation of many stored URL Metric, for given the URL /2025/02/09/hello-world/ before the query vars would be:

{
  "page": "",
  "monthnum": "02",
  "day": "09",
  "year": "2025",
  "name": "hello world"
}

And the computed slug: 444f4b29005699892e56d95554869001

But with sorting the query vars are:

{
  "day": "09",
  "monthnum": "02",
  "name": "hello world",
  "page": "",
  "year": "2025"
}

And the computed slug: 20e710c6349de2e10e382f872744b195

We should perhaps maintain a function like od_old_get_url_metrics_slug() which results in previous format so that when we try to look up the post by the old slug if the post with the new slug doesn't exist, and then it can update the slug with the new one.

The alternative to this would be to just let go of the old slugs. But this would mean all sites with Optimization Detective running would immediately cease from getting optimizations applied, since there would be none that have od_url_metrics posts with the new slugs in place.

Pro tip: The Optimization Detective Store Query Vars plugin is very helpful when looking wanting to see the underlying query vars that are behind a given od_url_metrics post slug.

westonruter avatar Mar 19 '25 22:03 westonruter

Codecov Report

Attention: Patch coverage is 80.00000% with 1 line in your changes missing coverage. Please review.

Project coverage is 71.08%. Comparing base (b5e1892) to head (f82ce84). Report is 1 commits behind head on trunk.

Files with missing lines Patch % Lines
plugins/optimization-detective/storage/data.php 80.00% 1 Missing :warning:
Additional details and impacted files
@@            Coverage Diff             @@
##            trunk    #1949      +/-   ##
==========================================
- Coverage   71.09%   71.08%   -0.01%     
==========================================
  Files          86       86              
  Lines        6970     6973       +3     
==========================================
+ Hits         4955     4957       +2     
- Misses       2015     2016       +1     
Flag Coverage Δ
multisite 71.08% <80.00%> (-0.01%) :arrow_down:
single 40.55% <20.00%> (-0.02%) :arrow_down:

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

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: 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.

codecov[bot] avatar Mar 19 '25 22:03 codecov[bot]

This issue has been resolved, please close it admin

phanduynam avatar Apr 03 '25 13:04 phanduynam