Skip to content

refactor(ads-client): restructure modules, strategy pattern for cache, clean MARS/client separation#7318

Merged
Almaju merged 2 commits intomozilla:mainfrom
Almaju:refactor/ads-client-restructure
Apr 15, 2026
Merged

refactor(ads-client): restructure modules, strategy pattern for cache, clean MARS/client separation#7318
Almaju merged 2 commits intomozilla:mainfrom
Almaju:refactor/ads-client-restructure

Conversation

@Almaju
Copy link
Copy Markdown
Contributor

@Almaju Almaju commented Apr 13, 2026

  • HttpCache: remove generic, extract CacheFirst/NetworkFirst into strategy.rs, extract CacheOutcome into outcome.rs, rename cache_control.ttl to effective_ttl
  • MARSClient: owns API types (ad_request, ad_response, error, environment, report_reason), builds AdRequest internally, creates viaduct Client per-request
  • AdsClient: pure orchestrator — no URL construction, no environment field, delegates all HTTP concerns to MARSClient
  • Errors split: mars/error.rs (HTTP/API errors), client/error.rs (orchestration errors), ffi/error.rs (FFI bridge errors)
  • Merge add_request_hash_to_callbacks + add_placement_info_to_report_callbacks into single enrich_callbacks pass
  • All methods &mut self -> &self

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.

@Almaju Almaju force-pushed the refactor/ads-client-restructure branch 5 times, most recently from d40ca48 to 9e872bd Compare April 13, 2026 22:26
@Almaju Almaju marked this pull request as ready for review April 13, 2026 22:26
@Almaju Almaju force-pushed the refactor/ads-client-restructure branch 2 times, most recently from 43babb5 to 5bbdfb6 Compare April 13, 2026 22:42
@Almaju Almaju enabled auto-merge April 13, 2026 23:13
@Almaju Almaju force-pushed the refactor/ads-client-restructure branch from 5bbdfb6 to d8a175d Compare April 14, 2026 16:11
/// `headers` are also excluded as they are request metadata, not cache keys.
impl Hash for AdRequest {
fn hash<H: Hasher>(&self, state: &mut H) {
self.url.as_str().hash(state);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I'm wondering if we should be storing the url query params for the hashing to be more robust?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@@ -199,17 +229,25 @@ mod tests {
.expect(1) // only first request goes to network
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

_m.assert is required for .expect to work properly!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Comment thread components/ads-client/src/http_cache.rs Outdated
@Almaju Almaju force-pushed the refactor/ads-client-restructure branch from 2a2b528 to 52919c7 Compare April 15, 2026 20:54
Almaju added 2 commits April 15, 2026 17:11
…, clean MARS/client separation

- HttpCache: remove generic, extract CacheFirst/NetworkFirst into strategy.rs,
extract CacheOutcome into outcome.rs, rename cache_control.ttl to effective_ttl
- MARSClient: owns API types (ad_request, ad_response, error, environment,
report_reason), builds AdRequest internally, creates viaduct Client per-request
- AdsClient: pure orchestrator — no URL construction, no environment field,
delegates all HTTP concerns to MARSClient
- Errors split: mars/error.rs (HTTP/API errors), client/error.rs (orchestration
errors), ffi/error.rs (FFI bridge errors)
- Merge add_request_hash_to_callbacks + add_placement_info_to_report_callbacks
into single enrich_callbacks pass
- All methods &mut self -> &self
HttpCacheError was a thin wrapper around rusqlite::Error — its Builder
variant was never used since the builder already returns
HttpCacheBuilderError directly.

Remove it and propagate rusqlite::Error through clear_cache and
invalidate_by_hash instead. Also splits CacheOutcome::StoreFailed
(insert/upsert failures) from the new TrimFailed (size trim failures),
and makes all error-bearing outcome variants consistent by using
rusqlite::Error directly, matching LookupFailed.
@Almaju Almaju force-pushed the refactor/ads-client-restructure branch from 52919c7 to 68bac7a Compare April 15, 2026 21:11
@Almaju Almaju added this pull request to the merge queue Apr 15, 2026
Merged via the queue into mozilla:main with commit df5c1f2 Apr 15, 2026
15 checks passed
@Almaju Almaju deleted the refactor/ads-client-restructure branch April 15, 2026 21:53
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