Skip to content

Commit

Permalink
Improve Brave ads serving pipeline performance
Browse files Browse the repository at this point in the history
  • Loading branch information
tmancey committed Oct 19, 2021
1 parent c47f0f4 commit 0ff00af
Show file tree
Hide file tree
Showing 114 changed files with 1,694 additions and 1,666 deletions.
1 change: 0 additions & 1 deletion components/brave_ads/test/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ source_set("brave_ads_unit_tests") {
"//brave/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/eligible_ads_features_unittest.cc",
"//brave/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/eligible_ads_features_util_unittest.cc",
"//brave/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/eligible_ads_predictor_util_unittest.cc",
"//brave/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/eligible_ads_util_unittest.cc",
"//brave/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/inline_content_ads/eligible_inline_content_ads_v1_unittest.cc",
"//brave/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/inline_content_ads/eligible_inline_content_ads_v2_unittest.cc",
"//brave/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/sample_ads_unittest.cc",
Expand Down
9 changes: 5 additions & 4 deletions vendor/bat-native-ads/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,8 @@ source_set("ads") {
"src/bat/ads/internal/ads/ad_notifications/ad_notification_permission_rules.h",
"src/bat/ads/internal/ads/ad_notifications/ad_notifications.cc",
"src/bat/ads/internal/ads/ad_notifications/ad_notifications.h",
"src/bat/ads/internal/ads/exclusion_rules_base.cc",
"src/bat/ads/internal/ads/exclusion_rules_base.h",
"src/bat/ads/internal/ads/inline_content_ads/inline_content_ad.cc",
"src/bat/ads/internal/ads/inline_content_ads/inline_content_ad.h",
"src/bat/ads/internal/ads/inline_content_ads/inline_content_ad_builder.cc",
Expand Down Expand Up @@ -492,7 +494,6 @@ source_set("ads") {
"src/bat/ads/internal/database/tables/geo_targets_database_table.h",
"src/bat/ads/internal/database/tables/segments_database_table.cc",
"src/bat/ads/internal/database/tables/segments_database_table.h",
"src/bat/ads/internal/eligible_ads/ad_notifications/eligible_ad_notifications_aliases.h",
"src/bat/ads/internal/eligible_ads/ad_notifications/eligible_ad_notifications_base.cc",
"src/bat/ads/internal/eligible_ads/ad_notifications/eligible_ad_notifications_base.h",
"src/bat/ads/internal/eligible_ads/ad_notifications/eligible_ad_notifications_factory.cc",
Expand All @@ -503,16 +504,16 @@ source_set("ads") {
"src/bat/ads/internal/eligible_ads/ad_notifications/eligible_ad_notifications_v2.h",
"src/bat/ads/internal/eligible_ads/ad_predictor_info.cc",
"src/bat/ads/internal/eligible_ads/ad_predictor_info.h",
"src/bat/ads/internal/eligible_ads/choose_ad.h",
"src/bat/ads/internal/eligible_ads/eligible_ads_aliases.h",
"src/bat/ads/internal/eligible_ads/eligible_ads_aliases.h",
"src/bat/ads/internal/eligible_ads/eligible_ads_constants.h",
"src/bat/ads/internal/eligible_ads/eligible_ads_features.cc",
"src/bat/ads/internal/eligible_ads/eligible_ads_features.h",
"src/bat/ads/internal/eligible_ads/eligible_ads_features_util.cc",
"src/bat/ads/internal/eligible_ads/eligible_ads_features_util.h",
"src/bat/ads/internal/eligible_ads/eligible_ads_predictor_util.h",
"src/bat/ads/internal/eligible_ads/eligible_ads_util.h",
"src/bat/ads/internal/eligible_ads/eligible_ads_util_aliases.h",
"src/bat/ads/internal/eligible_ads/inline_content_ads/eligible_inline_content_ads_aliases.h",
"src/bat/ads/internal/eligible_ads/frequency_capping.h",
"src/bat/ads/internal/eligible_ads/inline_content_ads/eligible_inline_content_ads_base.cc",
"src/bat/ads/internal/eligible_ads/inline_content_ads/eligible_inline_content_ads_base.h",
"src/bat/ads/internal/eligible_ads/inline_content_ads/eligible_inline_content_ads_factory.cc",
Expand Down
Binary file not shown.
12 changes: 6 additions & 6 deletions vendor/bat-native-ads/src/bat/ads/ad_event_history_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ class BatAdsAdEventHistoryTest : public UnitTestBase {
timestamp);
}

std::vector<double> GetAdEvent(const AdType& ad_type,
const ConfirmationType& confirmation_type) {
std::vector<double> GetAdEvents(const AdType& ad_type,
const ConfirmationType& confirmation_type) {
const std::string ad_type_as_string = std::string(ad_type);

const std::string confirmation_type_as_string =
Expand All @@ -51,7 +51,7 @@ TEST_F(BatAdsAdEventHistoryTest, RecordAdEventForNewType) {

// Act
const std::vector<double> history =
GetAdEvent(AdType::kAdNotification, ConfirmationType::kViewed);
GetAdEvents(AdType::kAdNotification, ConfirmationType::kViewed);

// Assert
const double timestamp = NowAsTimestamp();
Expand All @@ -66,7 +66,7 @@ TEST_F(BatAdsAdEventHistoryTest, RecordAdEventForExistingType) {

// Act
const std::vector<double> history =
GetAdEvent(AdType::kAdNotification, ConfirmationType::kViewed);
GetAdEvents(AdType::kAdNotification, ConfirmationType::kViewed);

// Assert
const double timestamp = NowAsTimestamp();
Expand All @@ -81,7 +81,7 @@ TEST_F(BatAdsAdEventHistoryTest, RecordAdEventForMultipleTypes) {

// Act
const std::vector<double> history =
GetAdEvent(AdType::kAdNotification, ConfirmationType::kViewed);
GetAdEvents(AdType::kAdNotification, ConfirmationType::kViewed);

// Assert
const double timestamp = NowAsTimestamp();
Expand All @@ -100,7 +100,7 @@ TEST_F(BatAdsAdEventHistoryTest, PurgeHistoryOlderThan) {

// Act
const std::vector<double> history =
GetAdEvent(AdType::kAdNotification, ConfirmationType::kViewed);
GetAdEvents(AdType::kAdNotification, ConfirmationType::kViewed);

// Assert
const double timestamp = NowAsTimestamp();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@
#include "base/time/time.h"
#include "bat/ads/confirmation_type.h"
#include "bat/ads/internal/ad_events/ad_event_info.h"
#include "bat/ads/internal/ad_events/ad_events.h"
#include "bat/ads/internal/bundle/creative_ad_info.h"
#include "bat/ads/internal/unittest_time_util.h"
#include "bat/ads/internal/unittest_util.h"

namespace ads {

AdEventInfo GetAdEvent(const CreativeAdInfo& creative_ad,
const ConfirmationType confirmation_type,
const base::Time& created_at) {
AdEventInfo BuildAdEvent(const CreativeAdInfo& creative_ad,
const ConfirmationType confirmation_type,
const base::Time& created_at) {
AdEventInfo ad_event;
ad_event.uuid = base::GenerateGUID();
ad_event.confirmation_type = confirmation_type;
Expand All @@ -26,4 +29,46 @@ AdEventInfo GetAdEvent(const CreativeAdInfo& creative_ad,
return ad_event;
}

AdEventInfo BuildAdEvent(const ConfirmationType confirmation_type) {
AdEventInfo ad_event;

ad_event.type = AdType::kAdNotification;
ad_event.uuid = base::GenerateGUID();
ad_event.confirmation_type = confirmation_type;
ad_event.campaign_id = base::GenerateGUID();
ad_event.creative_set_id = base::GenerateGUID();
ad_event.creative_instance_id = base::GenerateGUID();
ad_event.advertiser_id = base::GenerateGUID();
ad_event.created_at = Now();

return ad_event;
}

AdEventInfo BuildAdEvent(const std::string& uuid,
const std::string& creative_set_id,
const ConfirmationType confirmation_type) {
AdEventInfo ad_event;

ad_event.type = AdType::kAdNotification;
ad_event.uuid = uuid;
ad_event.confirmation_type = confirmation_type;
ad_event.campaign_id = "604df73f-bc6e-4583-a56d-ce4e243c8537";
ad_event.creative_set_id = creative_set_id;
ad_event.creative_instance_id = "7a3b6d9f-d0b7-4da6-8988-8d5b8938c94f";
ad_event.advertiser_id = "f646c5f5-027a-4a35-b081-fce85e830b19";
ad_event.created_at = Now();

return ad_event;
}

AdEventInfo BuildAdEvent(const std::string& creative_set_id,
const ConfirmationType confirmation_type) {
const std::string uuid = base::GenerateGUID();
return BuildAdEvent(uuid, creative_set_id, confirmation_type);
}

void FireAdEvent(const AdEventInfo& ad_event) {
LogAdEvent(ad_event, [](const bool success) { ASSERT_TRUE(success); });
}

} // namespace ads
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#ifndef BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_AD_EVENTS_AD_EVENT_UNITTEST_UTIL_H_
#define BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_AD_EVENTS_AD_EVENT_UNITTEST_UTIL_H_

#include <string>

namespace base {
class Time;
} // namespace base
Expand All @@ -16,9 +18,20 @@ class ConfirmationType;
struct AdEventInfo;
struct CreativeAdInfo;

AdEventInfo GetAdEvent(const CreativeAdInfo& creative_ad,
const ConfirmationType confirmation_type,
const base::Time& created_at);
AdEventInfo BuildAdEvent(const CreativeAdInfo& creative_ad,
const ConfirmationType confirmation_type,
const base::Time& created_at);

AdEventInfo BuildAdEvent(const ConfirmationType confirmation_type);

AdEventInfo BuildAdEvent(const std::string& uuid,
const std::string& creative_set_id,
const ConfirmationType confirmation_type);

AdEventInfo BuildAdEvent(const std::string& creative_set_id,
const ConfirmationType confirmation_type);

void FireAdEvent(const AdEventInfo& ad_event);

} // namespace ads

Expand Down
Loading

0 comments on commit 0ff00af

Please sign in to comment.