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

Fixes migration for old score bug #1519

Merged
merged 1 commit into from
Jan 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions vendor/bat-native-ledger/src/bat_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,7 @@ static bool ignore_ = false;
allow_videos_ = state.allow_videos_;
monthly_balances_ = state.monthly_balances_;
recurring_donation_ = state.recurring_donation_;
migrate_score = state.migrate_score;
}

PUBLISHER_STATE_ST::~PUBLISHER_STATE_ST() {}
Expand Down Expand Up @@ -661,6 +662,7 @@ static bool ignore_ = false;
monthly_balances_.insert(std::make_pair(itr->name.GetString(), r));
}
}

for (const auto & i : d["recurring_donation"].GetArray()) {
rapidjson::StringBuffer sb;
rapidjson::Writer<rapidjson::StringBuffer> writer(sb);
Expand All @@ -674,6 +676,12 @@ static bool ignore_ = false;
recurring_donation_.insert(std::make_pair(itr->name.GetString(), itr->value.GetDouble()));
}
}

if (d.HasMember("migrate_score") && d["migrate_score"].IsBool()) {
migrate_score = d["migrate_score"].GetBool();
} else {
migrate_score = true;
}
}

return !error;
Expand Down Expand Up @@ -718,8 +726,12 @@ static bool ignore_ = false;
writer.Double(p.second);
writer.EndObject();
}

writer.EndArray();

writer.String("migrate_score");
writer.Bool(data.migrate_score);

writer.EndObject();
}

Expand Down
1 change: 1 addition & 0 deletions vendor/bat-native-ledger/src/bat_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ namespace braveledger_bat_helper {
bool allow_videos_ = true;
std::map<std::string, REPORT_BALANCE_ST> monthly_balances_;
std::map<std::string, double> recurring_donation_;
bool migrate_score = false;
};

struct PUBLISHER_ST {
Expand Down
21 changes: 17 additions & 4 deletions vendor/bat-native-ledger/src/bat_publishers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,15 @@ bool BatPublishers::getPublisherAllowVideos() const {
return state_->allow_videos_;
}

bool BatPublishers::GetMigrateScore() const {
return state_->migrate_score;
}

void BatPublishers::SetMigrateScore(bool value) {
state_->migrate_score = value;
saveState();
}

void BatPublishers::NormalizeContributeWinners(
ledger::PublisherInfoList* newList,
bool saveData,
Expand All @@ -547,11 +556,16 @@ void BatPublishers::synopsisNormalizerInternal(
for (size_t i = 0; i < list.size(); i++) {
// Check which would test uint problem from this issue
// https://github.com/brave/brave-browser/issues/3134
if (list[i].score < -100000) {
if (GetMigrateScore()) {
list[i].score = concaveScore(list[i].duration);
}
totalScores += list[i].score;
}

if (GetMigrateScore()) {
SetMigrateScore(false);
}

std::vector<unsigned int> percents;
std::vector<double> weights;
std::vector<double> realPercents;
Expand Down Expand Up @@ -668,9 +682,8 @@ bool BatPublishers::isEligibleForContribution(const ledger::PublisherInfo& info)
if (isExcluded(info.id, info.excluded) || (!state_->allow_non_verified_ && !isVerified(info.id)))
return false;

return info.score > 0 &&
info.duration >= state_->min_publisher_duration_ &&
info.visits >= state_->min_visits_;
return info.duration >= state_->min_publisher_duration_ &&
info.visits >= state_->min_visits_;

}

Expand Down
4 changes: 4 additions & 0 deletions vendor/bat-native-ledger/src/bat_publishers.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ class BatPublishers : public ledger::LedgerCallbackHandler {
void synopsisNormalizerInternal(ledger::PublisherInfoList* newList, bool saveData,
const ledger::PublisherInfoList& list, uint32_t /* next_record */);

bool GetMigrateScore() const;

void SetMigrateScore(bool value);

bool isPublisherVisible(const braveledger_bat_helper::PUBLISHER_ST& publisher_st);

void onPublisherActivity(ledger::Result result,
Expand Down