Skip to content

Commit

Permalink
Merge pull request #1519 from brave/score-fix-migration-59
Browse files Browse the repository at this point in the history
Fixes migration for old score bug
  • Loading branch information
NejcZdovc authored Jan 30, 2019
2 parents 0f01759 + ac06429 commit 97038a4
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 deletions.
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

0 comments on commit 97038a4

Please sign in to comment.