Improve query var normalization #1949
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:And the computed slug:
444f4b29005699892e56d95554869001
But with sorting the query vars are:
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.