Skip to content

Commit

Permalink
Adds support for auto contributions
Browse files Browse the repository at this point in the history
  • Loading branch information
NejcZdovc committed Oct 10, 2018
1 parent 30e8b42 commit 082470a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ deps = {
"vendor/boto": "https://github.com/boto/boto@f7574aa6cc2c819430c1f05e9a1a1a666ef8169b",
"vendor/python-patch": "https://github.com/svn2github/python-patch@a336a458016ced89aba90dfc3f4c8222ae3b1403",
"vendor/sparkle": "https://github.com/brave/Sparkle.git@c0759cce415d7c0feae45005c8a013b1898711f0",
"vendor/bat-native-ledger": "https://github.com/brave-intl/bat-native-ledger@fe65bbb07d8e3ef237ada14b54dd9390f12fc2ee",
"vendor/bat-native-ledger": "https://github.com/brave-intl/bat-native-ledger@0fbc45fbaa2267dba8ae6dbcf9e4f74517bdf273",
"vendor/bat-native-rapidjson": "https://github.com/brave-intl/bat-native-rapidjson.git@86aafe2ef89835ae71c9ed7c2527e3bb3000930e",
"vendor/bip39wally-core-native": "https://github.com/brave-intl/bip39wally-core-native.git@9b119931c702d55be994117eb505d56310720b1d",
"vendor/bat-native-anonize": "https://github.com/brave-intl/bat-native-anonize.git@0559543f458a949b83b58035273ef7f8f1a1b111",
Expand Down
21 changes: 16 additions & 5 deletions components/brave_rewards/browser/publisher_info_database.cc
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ bool PublisherInfoDatabase::CreateActivityInfoTable() {
"category INTEGER NOT NULL,"
"month INTEGER NOT NULL,"
"year INTEGER NOT NULL,"
"reconcile_stamp INTEGER DEFAULT 0 NOT NULL,"
"CONSTRAINT fk_activity_info_publisher_id"
" FOREIGN KEY (publisher_id)"
" REFERENCES publisher_info (publisher_id)"
Expand Down Expand Up @@ -226,12 +227,13 @@ bool PublisherInfoDatabase::InsertOrUpdatePublisherInfo(
sql::Statement activity_get(
db_.GetUniqueStatement("SELECT publisher_id FROM activity_info WHERE "
"publisher_id=? AND category=? "
"AND month=? AND year=?"));
"AND month=? AND year=? AND reconcile_stamp=?"));

activity_get.BindString(0, info.id);
activity_get.BindInt(1, info.category);
activity_get.BindInt(2, info.month);
activity_get.BindInt(3, info.year);
activity_get.BindInt64(4, info.reconcile_stamp);

if (activity_get.Step()) {
sql::Statement activity_info_update(
Expand All @@ -240,7 +242,7 @@ bool PublisherInfoDatabase::InsertOrUpdatePublisherInfo(
"duration=?, score=?, percent=?, "
"weight=? WHERE "
"publisher_id=? AND category=? "
"AND month=? AND year=?"));
"AND month=? AND year=? AND reconcile_stamp=?"));

activity_info_update.BindInt64(0, (int)info.duration);
activity_info_update.BindDouble(1, info.score);
Expand All @@ -250,6 +252,7 @@ bool PublisherInfoDatabase::InsertOrUpdatePublisherInfo(
activity_info_update.BindInt(5, info.category);
activity_info_update.BindInt(6, info.month);
activity_info_update.BindInt(7, info.year);
activity_info_update.BindInt64(8, info.reconcile_stamp);

return activity_info_update.Run();
}
Expand All @@ -258,8 +261,8 @@ bool PublisherInfoDatabase::InsertOrUpdatePublisherInfo(
GetDB().GetCachedStatement(SQL_FROM_HERE,
"INSERT INTO activity_info "
"(publisher_id, duration, score, percent, "
"weight, category, month, year) "
"VALUES (?, ?, ?, ?, ?, ?, ?, ?)"));
"weight, category, month, year, reconcile_stamp) "
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"));

activity_info_insert.BindString(0, info.id);
activity_info_insert.BindInt64(1, (int)info.duration);
Expand All @@ -269,6 +272,7 @@ bool PublisherInfoDatabase::InsertOrUpdatePublisherInfo(
activity_info_insert.BindInt(5, info.category);
activity_info_insert.BindInt(6, info.month);
activity_info_insert.BindInt(7, info.year);
activity_info_insert.BindInt64(8, info.reconcile_stamp);

return activity_info_insert.Run();
}
Expand Down Expand Up @@ -340,7 +344,7 @@ bool PublisherInfoDatabase::Find(int start,

std::string query = "SELECT ai.publisher_id, ai.duration, ai.score, ai.percent, "
"ai.weight, pi.verified, pi.excluded, ai.category, ai.month, ai.year, pi.name, "
"pi.url, pi.provider, pi.favIcon "
"pi.url, pi.provider, pi.favIcon, ai.reconcile_stamp "
"FROM activity_info AS ai "
"INNER JOIN publisher_info AS pi ON ai.publisher_id = pi.publisher_id "
"WHERE 1 = 1";
Expand Down Expand Up @@ -368,6 +372,7 @@ bool PublisherInfoDatabase::Find(int start,
info.url = info_sql.ColumnString(11);
info.provider = info_sql.ColumnString(12);
info.favicon_url = info_sql.ColumnString(13);
info.reconcile_stamp = info_sql.ColumnInt64(14);

info.excluded = static_cast<ledger::PUBLISHER_EXCLUDE>(info_sql.ColumnInt(6));
info.category =
Expand Down Expand Up @@ -422,6 +427,9 @@ std::string PublisherInfoDatabase::BuildClauses(int start,
if (filter.year > 0)
clauses += " AND ai.year = ?";

if (filter.reconcile_stamp > 0)
clauses += " AND ai.reconcile_stamp = ?";

if (filter.min_duration > 0)
clauses += " AND ai.duration >= ?";

Expand Down Expand Up @@ -459,6 +467,9 @@ void PublisherInfoDatabase::BindFilter(sql::Statement& statement,
if (filter.year > 0)
statement.BindInt(column++, filter.year);

if (filter.reconcile_stamp > 0)
statement.BindInt64(column++, filter.reconcile_stamp);

if (filter.min_duration > 0)
statement.BindInt(column++, filter.min_duration);

Expand Down

0 comments on commit 082470a

Please sign in to comment.