Skip to content

Commit

Permalink
Merge pull request #161 from brave-intl/visit-exclude-recalc
Browse files Browse the repository at this point in the history
Percentage values are now recalculated correctly after excluding sites.
  • Loading branch information
NejcZdovc authored Oct 29, 2018
2 parents 0396fb4 + 54b6dd0 commit 3ce25e3
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 16 deletions.
10 changes: 9 additions & 1 deletion include/bat/ledger/publisher_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ LEDGER_EXPORT enum PUBLISHER_EXCLUDE {
INCLUDED = 2 // user manually changed it to include and is overriding server flags
};

LEDGER_EXPORT enum PUBLISHER_EXCLUDE_FILTER {
FILTER_ALL = -1,
FILTER_DEFAULT = 0,
FILTER_EXCLUDED = 1,
FILTER_INCLUDED = 2,
FILTER_ALL_EXCEPT_EXCLUDED = 3
};

LEDGER_EXPORT struct PublisherInfoFilter {
PublisherInfoFilter();
PublisherInfoFilter(const PublisherInfoFilter& filter);
Expand All @@ -53,7 +61,7 @@ LEDGER_EXPORT struct PublisherInfoFilter {
int category;
PUBLISHER_MONTH month;
int year;
PUBLISHER_EXCLUDE excluded;
PUBLISHER_EXCLUDE_FILTER excluded;
std::vector<std::pair<std::string, bool>> order_by;
unsigned int min_duration;
uint64_t reconcile_stamp;
Expand Down
2 changes: 1 addition & 1 deletion src/bat/ledger/ledger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ PublisherInfoFilter::PublisherInfoFilter() :
category(PUBLISHER_CATEGORY::ALL_CATEGORIES),
month(PUBLISHER_MONTH::ANY),
year(-1),
excluded(PUBLISHER_EXCLUDE::DEFAULT),
excluded(PUBLISHER_EXCLUDE_FILTER::FILTER_DEFAULT),
min_duration(0),
reconcile_stamp(0) {}
PublisherInfoFilter::PublisherInfoFilter(const PublisherInfoFilter& filter) :
Expand Down
31 changes: 20 additions & 11 deletions src/bat_publishers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ void BatPublishers::saveVisit(const std::string& publisher_id,
ledger::PUBLISHER_CATEGORY::AUTO_CONTRIBUTE,
visit_data.local_month,
visit_data.local_year,
ledger::PUBLISHER_EXCLUDE::ALL,
ledger::PUBLISHER_EXCLUDE_FILTER::FILTER_ALL,
false,
ledger_->GetReconcileStamp());

Expand All @@ -133,7 +133,7 @@ ledger::PublisherInfoFilter BatPublishers::CreatePublisherFilter(
category,
month,
year,
ledger::PUBLISHER_EXCLUDE::ALL,
ledger::PUBLISHER_EXCLUDE_FILTER::FILTER_ALL,
true,
0);
}
Expand All @@ -143,7 +143,7 @@ ledger::PublisherInfoFilter BatPublishers::CreatePublisherFilter(
ledger::PUBLISHER_CATEGORY category,
ledger::PUBLISHER_MONTH month,
int year,
ledger::PUBLISHER_EXCLUDE excluded) {
ledger::PUBLISHER_EXCLUDE_FILTER excluded) {
return CreatePublisherFilter(publisher_id,
category,
month,
Expand All @@ -163,7 +163,7 @@ ledger::PublisherInfoFilter BatPublishers::CreatePublisherFilter(
category,
month,
year,
ledger::PUBLISHER_EXCLUDE::ALL,
ledger::PUBLISHER_EXCLUDE_FILTER::FILTER_ALL,
min_duration,
0);
}
Expand All @@ -173,7 +173,7 @@ ledger::PublisherInfoFilter BatPublishers::CreatePublisherFilter(
ledger::PUBLISHER_CATEGORY category,
ledger::PUBLISHER_MONTH month,
int year,
ledger::PUBLISHER_EXCLUDE excluded,
ledger::PUBLISHER_EXCLUDE_FILTER excluded,
bool min_duration,
const uint64_t& currentReconcileStamp) {
ledger::PublisherInfoFilter filter;
Expand Down Expand Up @@ -291,7 +291,7 @@ void BatPublishers::setExclude(const std::string& publisher_id, const ledger::PU
ledger::PUBLISHER_CATEGORY::AUTO_CONTRIBUTE,
ledger::PUBLISHER_MONTH::ANY,
-1,
ledger::PUBLISHER_EXCLUDE::ALL,
ledger::PUBLISHER_EXCLUDE_FILTER::FILTER_ALL,
false,
currentReconcileStamp);
ledger_->GetPublisherInfo(filter, std::bind(&BatPublishers::onSetExcludeInternal,
Expand All @@ -305,7 +305,7 @@ void BatPublishers::setPanelExclude(const std::string& publisher_id,
ledger::PUBLISHER_CATEGORY::AUTO_CONTRIBUTE,
ledger::PUBLISHER_MONTH::ANY,
-1,
ledger::PUBLISHER_EXCLUDE::ALL,
ledger::PUBLISHER_EXCLUDE_FILTER::FILTER_ALL,
false,
currentReconcileStamp);
ledger_->GetPublisherInfo(filter, std::bind(
Expand Down Expand Up @@ -337,10 +337,19 @@ void BatPublishers::onSetExcludeInternal(ledger::PUBLISHER_EXCLUDE exclude,
setNumExcludedSitesInternal(exclude);

ledger_->SetPublisherInfo(std::move(publisher_info),
std::bind(&onVisitSavedDummy, _1, _2));
std::bind(&BatPublishers::onSetPublisherInfo, this, _1, _2));

OnExcludedSitesChanged();
}

void BatPublishers::onSetPublisherInfo(ledger::Result result,
std::unique_ptr<ledger::PublisherInfo> publisher_info) {
if (result != ledger::Result::LEDGER_OK) {
return;
}
synopsisNormalizer(*publisher_info);
}

void BatPublishers::onSetPanelExcludeInternal(ledger::PUBLISHER_EXCLUDE exclude,
uint64_t windowId,
ledger::Result result,
Expand Down Expand Up @@ -378,7 +387,7 @@ void BatPublishers::restorePublishers() {
ledger::PUBLISHER_CATEGORY::AUTO_CONTRIBUTE,
ledger::PUBLISHER_MONTH::ANY,
-1,
ledger::PUBLISHER_EXCLUDE::EXCLUDED,
ledger::PUBLISHER_EXCLUDE_FILTER::FILTER_EXCLUDED,
false,
currentReconcileStamp);
ledger_->GetPublisherInfoList(0, 0, filter, std::bind(&BatPublishers::onRestorePublishersInternal,
Expand Down Expand Up @@ -548,7 +557,7 @@ void BatPublishers::synopsisNormalizer(const ledger::PublisherInfo& info) {
ledger::PUBLISHER_CATEGORY::AUTO_CONTRIBUTE,
info.month,
info.year,
ledger::PUBLISHER_EXCLUDE::DEFAULT,
ledger::PUBLISHER_EXCLUDE_FILTER::FILTER_ALL_EXCEPT_EXCLUDED,
true,
ledger_->GetReconcileStamp());
// TODO SZ: We pull the whole list currently, I don't think it consumes lots of RAM, but could.
Expand Down Expand Up @@ -864,7 +873,7 @@ void BatPublishers::getPublisherActivityFromUrl(uint64_t windowId, const ledger:
ledger::PUBLISHER_CATEGORY::AUTO_CONTRIBUTE,
visit_data.local_month,
visit_data.local_year,
ledger::PUBLISHER_EXCLUDE::ALL,
ledger::PUBLISHER_EXCLUDE_FILTER::FILTER_ALL,
false,
ledger_->GetReconcileStamp());

Expand Down
6 changes: 4 additions & 2 deletions src/bat_publishers.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class BatPublishers : public ledger::LedgerCallbackHandler {
ledger::PUBLISHER_CATEGORY category,
ledger::PUBLISHER_MONTH month,
int year,
ledger::PUBLISHER_EXCLUDE excluded);
ledger::PUBLISHER_EXCLUDE_FILTER excluded);

ledger::PublisherInfoFilter CreatePublisherFilter(
const std::string& publisher_id,
Expand All @@ -122,7 +122,7 @@ class BatPublishers : public ledger::LedgerCallbackHandler {
ledger::PUBLISHER_CATEGORY category,
ledger::PUBLISHER_MONTH month,
int year,
ledger::PUBLISHER_EXCLUDE excluded,
ledger::PUBLISHER_EXCLUDE_FILTER excluded,
bool min_duration,
const uint64_t& currentReconcileStamp);

Expand All @@ -135,6 +135,8 @@ class BatPublishers : public ledger::LedgerCallbackHandler {

// LedgerCallbackHandler impl
void OnPublisherStateSaved(ledger::Result result) override;
void onSetPublisherInfo(ledger::Result result,
std::unique_ptr<ledger::PublisherInfo> publisher_info);

bool isEligibleForContribution(const ledger::PublisherInfo& info);
bool isVerified(const std::string& publisher_id);
Expand Down
2 changes: 1 addition & 1 deletion src/ledger_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ void LedgerImpl::StartAutoContribute () {
ledger::PUBLISHER_CATEGORY::AUTO_CONTRIBUTE,
ledger::PUBLISHER_MONTH::ANY,
-1,
ledger::PUBLISHER_EXCLUDE::DEFAULT,
ledger::PUBLISHER_EXCLUDE_FILTER::FILTER_DEFAULT,
true,
currentReconcileStamp
);
Expand Down

0 comments on commit 3ce25e3

Please sign in to comment.