Skip to content

refactor(ads-client): changed AdRequest.url to be environment for a more stable hashing#7368

Open
copyrighthero wants to merge 1 commit into
mozilla:mainfrom
copyrighthero:feat/ac-101--refactor-ad-request-remove-url
Open

refactor(ads-client): changed AdRequest.url to be environment for a more stable hashing#7368
copyrighthero wants to merge 1 commit into
mozilla:mainfrom
copyrighthero:feat/ac-101--refactor-ad-request-remove-url

Conversation

@copyrighthero
Copy link
Copy Markdown
Contributor

This PR refactors the internal impl of the AdRequest struct and its hash method by switching the url attribute to be environment instead, this way the generated hashing is more stable unless the response shape changes.

Since this is AdsClient internal implementation refactor, it is non-breaking and should not be detailed in the CHANGELOG documentation.

Pull Request checklist

  • Breaking changes: This PR follows our breaking change policy
    • This PR follows the breaking change policy:
      • This PR has no breaking API changes, or
      • There are corresponding PRs for our consumer applications that resolve the breaking changes and have been approved
  • Quality: This PR builds and tests run cleanly
    • Note:
      • For changes that need extra cross-platform testing, consider adding [ci full] to the PR title.
      • If this pull request includes a breaking change, consider cutting a new release after merging.
  • Tests: This PR includes thorough tests or an explanation of why it does not
  • Changelog: This PR includes a changelog entry in CHANGELOG.md or an explanation of why it does not need one
    • Any breaking changes to Swift or Kotlin binding APIs are noted explicitly
  • Dependencies: This PR follows our dependency management guidelines
    • Any new dependencies are accompanied by a summary of the due diligence applied in selecting them.

@copyrighthero copyrighthero requested a review from Almaju May 13, 2026 16:50
…nt instead for the cache hashing to be more stable.
@copyrighthero copyrighthero force-pushed the feat/ac-101--refactor-ad-request-remove-url branch from 8c22cc2 to 34847d8 Compare May 13, 2026 16:55
Comment on lines 24 to 33
pub fn into_url(self, path: &str) -> Url {
let mut base = self.base_url();
// Ensure the path has a trailing slash so that `join` appends
// rather than replacing the last segment.
if !base.path().ends_with('/') {
base.set_path(&format!("{}/", base.path()));
}
base.join(path)
.expect("joining a path to a valid base URL must succeed")
}
Copy link
Copy Markdown
Contributor

@Almaju Almaju May 13, 2026

Choose a reason for hiding this comment

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

nit: I realize this function is not properly tested, I can create a ticket for this but I'd like to make sure that for example: into_url("/ads") == into_url("ads")


use super::error::BuildRequestError;

const ENDPOINT: &str = "ads";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: Perhaps we could change this to "/ads", I think it feels nicer when talking about endpoint to have a leading slash but this requires https://github.com/mozilla/application-services/pull/7368/changes#r3236429333 first I think.

fn hash<H: Hasher>(&self, state: &mut H) {
self.url.as_str().hash(state);
self.placements.hash(state);
self.environment.hash(state);
Copy link
Copy Markdown
Contributor

@Almaju Almaju May 13, 2026

Choose a reason for hiding this comment

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

nit: I would just add ENDPOINT.hash(state); to bind the hash to the endpoint so if tomorrow we have a /v2/ads we wont have hash clashing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants