Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ads] Optimize resource loading #23792

Merged
merged 1 commit into from
Jun 10, 2024
Merged

[ads] Optimize resource loading #23792

merged 1 commit into from
Jun 10, 2024

Conversation

tmancey
Copy link
Collaborator

@tmancey tmancey commented May 22, 2024

Resolves brave/brave-browser#38505

Submitter Checklist:

  • I confirm that no security/privacy review is needed and no other type of reviews are needed, or that I have requested them
  • There is a ticket for my issue
  • Used Github auto-closing keywords in the PR description above
  • Wrote a good PR/commit description
  • Squashed any review feedback or "fixup" commits before merge, so that history is a record of what happened in the repo, not your PR
  • Added appropriate labels (QA/Yes or QA/No; release-notes/include or release-notes/exclude; OS/...) to the associated issue
  • Checked the PR locally:
    • npm run test -- brave_browser_tests, npm run test -- brave_unit_tests wiki
    • npm run presubmit wiki, npm run gn_check, npm run tslint
  • Ran git rebase master (if needed)

Reviewer Checklist:

  • A security review is not needed, or a link to one is included in the PR description
  • New files have MPL-2.0 license header
  • Adequate test coverage exists to prevent regressions
  • Major classes, functions and non-trivial code blocks are well-commented
  • Changes in component dependencies are properly reflected in gn
  • Code follows the style guide
  • Test plan is specified in PR before merging

After-merge Checklist:

Test Plan:

Resource test plans:

Ensure the following resources are loaded and that the log shows Successfully loaded and parsed ... resource version when the requirements are met. If the requirements are not met, the resources should be unloaded. Ensure that resource updates are applied. Malformed resources should fail to load and display Failed to load and parse ... resource in the logs. Unavailable resources should display ... resource is unavailable in the logs.

Require catalog resource only if:

  • The user has opted into Brave News ads.
  • The user has opted into new tab page ads and has either joined Brave Rewards or new tab page ad events should always be triggered.
  • The user has joined Brave Rewards and opted into notification ads.

Require anti-targeting resource only if:

  • The user has opted into Brave News ads.
  • The user has opted into new tab page ads and has either joined Brave Rewards or new tab page ad events should always be triggered.
  • The user has joined Brave Rewards and opted into notification ads.

Require purchase intent resource only if:

  • The user has joined Brave Rewards and opted into notification ads.

Require text classification resource only if:

  • The user has joined Brave Rewards and opted into notification ads.

Require conversion resource only if:

  • The user has joined Brave Rewards and opted into Brave News ads, new tab page ads, notification ads, or search result ads.

Other test plans:

Ensure the following features are supported when the requirements are met. If the requirements are not met, the features should not be supported.

Trigger a verifiable conversion only if:

  • The user has joined Brave Rewards and opted into Brave News ads, new tab page ads, notification ads, or search result ads.

Fetch subdivision (geo.ads.brave.com) only if:

  • The user has opted into Brave News ads.
  • The user has opted into new tab page ads and has either joined Brave Rewards or new tab page ad events should always be triggered.
  • The user has joined Brave Rewards and opted into notification ads.

Allow subdivision targeting (frequency capping) for United States of America or Canada only if:

  • User has opted into Brave News ads.
  • User has opted into new tab page ads and either joined Brave Rewards or new tab page ad events should always be triggered.
  • User has joined Brave Rewards and opted into notification ads.

@tmancey tmancey self-assigned this May 22, 2024
@tmancey tmancey requested a review from a team as a code owner May 22, 2024 22:51
@tmancey tmancey marked this pull request as draft May 22, 2024 22:51
@tmancey tmancey force-pushed the issues/38505 branch 2 times, most recently from 94a38aa to ac206b6 Compare May 28, 2024 11:16
@tmancey tmancey changed the title [ads] Only load conversion resource if the user has joined Brave Rewards and opted in to see ads [ads] Optimizes resource loading May 28, 2024
@tmancey tmancey changed the title [ads] Optimizes resource loading [ads] Optimize resource loading May 28, 2024
@tmancey tmancey force-pushed the issues/38505 branch 23 times, most recently from d1cdebf to 61fa96b Compare June 4, 2024 07:00
@tmancey tmancey removed CI/skip-macos-x64 Do not run CI builds for macOS x64 CI/skip-ios Do not run CI builds for iOS CI/skip-upstream-tests Do not run upstream unit and browser tests (otherwise run on Linux) CI/skip-windows-x64 Do not run CI builds for Windows x64 CI/skip-all-linters Do not run linters and presubmit checks labels Jun 7, 2024
@tmancey tmancey force-pushed the issues/38505 branch 14 times, most recently from d717531 to dd91d93 Compare June 7, 2024 12:13
@tmancey tmancey enabled auto-merge June 7, 2024 15:35
@tmancey tmancey force-pushed the issues/38505 branch 2 times, most recently from 04647d5 to a2ef9a8 Compare June 10, 2024 10:22
Copy link
Contributor

[puLL-Merge] - brave/brave-core@23792

Here is my review of the pull request:

Description

This PR makes several changes related to loading and unloading of resources in the Brave Ads component. The main changes include:

  • Renaming some functions and variables for clarity and consistency
  • Adding checks for various ad preferences before deciding whether to load certain resources
  • Logging more details when registering, updating and unregistering resource components
  • Cleaning up some code and fixing minor issues

The motivation seems to be to improve the resource loading logic to only load resources when actually needed based on the user's Brave Rewards status and ad preference settings. This should help with performance and efficiency.

Changes

Changes

  • components/brave_ads/core/internal/account/account.cc: Added IsUserRewardsSupported() function. Updated resource loading to check ad preferences.
  • components/brave_ads/core/internal/catalog/catalog.cc: Updated logic for deciding when the resource is required
  • components/brave_ads/core/internal/client/ads_client_notifier.cc: Made Notify* functions non-const. Added early returns when queueing notifications.
  • components/brave_ads/core/internal/common/resources/resource_util.h: Renamed ResourceParsingErrorOr -> ResourceComponentParsingErrorOr, LoadAndParseResourceCallback -> LoadAndParseResourceComponentCallback
  • components/brave_ads/core/internal/common/subdivision/subdivision.cc: Updated resource loading logic
  • components/brave_ads/core/internal/prefs/pref_util.cc: Added helper functions to check ad preference paths
  • components/brave_ads/core/internal/targeting/behavioral/anti_targeting/resource/anti_targeting_resource.cc: Renamed load/reset functions, added logic checks
  • Similar renaming and logic updates to other resource loading classes

Possible Issues

No major issues found. The changes look reasonable and well-structured. A few observations:

  • There is now a dependency between resource loading and ad preference flags. Need to ensure this doesn't cause any unexpected behaviors.
  • Should verify through testing that resources are loaded and unloaded at the appropriate times based on the new logic

Security Hotspots

None found. The changes don't seem to introduce any new security risks.

In summary, this is a reasonably-sized refactoring PR that aims to optimize resource loading in Brave Ads. The individual changes make sense and the overall direction looks good. I would suggest thorough testing to verify correct behavior with the updated logic, but I did not see any red flags in the code itself. It should be okay to merge after addressing any minor feedback and confirming it works as expected.

@tmancey tmancey merged commit d05bd7d into master Jun 10, 2024
19 checks passed
@tmancey tmancey deleted the issues/38505 branch June 10, 2024 14:42
@github-actions github-actions bot added this to the 1.69.x - Nightly milestone Jun 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants