refactor(ads-client): changed AdRequest.url to be environment for a more stable hashing#7368
Open
copyrighthero wants to merge 1 commit into
Open
Conversation
…nt instead for the cache hashing to be more stable.
8c22cc2 to
34847d8
Compare
Almaju
approved these changes
May 13, 2026
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") | ||
| } |
Contributor
There was a problem hiding this comment.
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"; |
Contributor
There was a problem hiding this comment.
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); |
Contributor
There was a problem hiding this comment.
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
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.
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
[ci full]to the PR title.