Skip to content

Improve query var normalization #1949

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

Draft
wants to merge 6 commits into
base: trunk
Choose a base branch
from

Conversation

westonruter
Copy link
Member

@westonruter westonruter commented Mar 19, 2025

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.

((Update 2025-08-09: The WP_Query for obtaining the URL Metrics post can simply provide an array of slugs. If multiples are returned due to there being URL Metrics stored with an old slug, then they should be merged with any new posts. At the point of update, the old post(s) should be deleted.))

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 westonruter added [Type] Bug An existing feature is broken [Plugin] Optimization Detective Issues for the Optimization Detective plugin labels Mar 19, 2025
Copy link

codecov bot commented Mar 19, 2025

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 ⚠️
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%) ⬇️
single 40.55% <20.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.

@phanduynam

This comment was marked as spam.

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] Bug An existing feature is broken
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants