Tolerate URL normalization differences in cache lookups#1317
Merged
Conversation
Register a `urls_eq` SQLite scalar function that compares two URL strings via `ParsedUrl` parsing (with raw-string fast path) and use it in `WHERE urls_eq(url, ?)` for `self_hosted_sites.url` reads. Lookups now match the same site whether it was stored as `http://localhost` or `http://localhost/`, which fixes the trunk integration-test break in `test_remove_site.rs` and removes the latent risk of duplicate rows on devices upgrading across PR #1239. Replaces the narrower `url_candidates` workaround (and the `delete_self_hosted_site_by_url(&[String])` overload that consumed it), so every URL-keyed read goes through one mechanism.
`register_url_functions` can fail at the SQLite layer; switch the impl from `From<Connection>` to `TryFrom<Connection>` so callers surface the error as `SqliteDbError` rather than panic. The four existing call sites are unit-test setup, which now `.expect(...)` the result.
Contributor
|
I am reviewing this as-is, but I wonder if it'd be better to handle the existing data through a migration and normalize the insert/look-up instead of trying to work around it. |
Contributor
Author
|
My main concern is that we'll have new code to insert random strings as "site url". To ensure the stored url exactly matches I don't like this approach because:
|
Collaborator
XCFramework BuildThis PR's XCFramework is available for testing. Add to your .package(url: "https://github.com/automattic/wordpress-rs", branch: "pr-build/1317")Built from 84e0f98 |
oguzkocer
approved these changes
May 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
Two integration tests in
wp_mobile_integration_tests/tests/test_remove_site.rspanicked withsite should exist. The root cause was an interaction between two PRs that landed in sequence on trunk:test_remove_site.rs, which looks up the test site with the raw credentials stringhttp://localhost, and aurl_candidatesworkaround that tolerates trailing-slash differences but only on the delete path.WpServiceto accept URLs asArc<ParsedUrl>and store them viaParsedUrl::url(), which normalizeshttp://localhosttohttp://localhost/.Neither PR's CI saw the combination. Post-merge on trunk, the cache stored the normalized form (
http://localhost/) while the tests still queried the raw form (http://localhost), andselect_self_hosted_site_by_url's bareWHERE url = ?lookup returnedNone. The trailing-slash tolerance fromurl_candidateshad never been wired into the read path.Changes
Register a
urls_eq(a, b)SQLite UDF that compares URLs viaParsedUrlparsing, replaceWHERE url = ?withWHERE urls_eq(url, ?)inselect_self_hosted_site_by_url, and removeurl_candidates. Every URL-keyed read now uses a single tolerant mechanism, so historical caches stored in any normalization shape continue to match.Test plan
CI green.
Changelog
CHANGELOG.mdunder## [Unreleased], using the Keep a Changelog categories (Added,Changed,Deprecated,Removed,Fixed,Security). Prefix breaking changes with**BREAKING:**.