diff --git a/components/brave_rewards/browser/publisher_info_database.cc b/components/brave_rewards/browser/publisher_info_database.cc index 4a7145a8252c..848220b8b659 100644 --- a/components/brave_rewards/browser/publisher_info_database.cc +++ b/components/brave_rewards/browser/publisher_info_database.cc @@ -24,14 +24,15 @@ namespace brave_rewards { namespace { -const int kCurrentVersionNumber = 5; +const int kCurrentVersionNumber = 6; const int kCompatibleVersionNumber = 1; } // namespace PublisherInfoDatabase::PublisherInfoDatabase(const base::FilePath& db_path) : db_path_(db_path), - initialized_(false) { + initialized_(false), + testing_current_version_(-1) { DETACH_FROM_SEQUENCE(sequence_checker_); } @@ -187,7 +188,7 @@ void PublisherInfoDatabase::GetTips(ledger::PublisherInfoList* list, while (info_sql.Step()) { std::string id(info_sql.ColumnString(0)); - ledger::PublisherInfo publisher(id, ledger::ACTIVITY_MONTH::ANY, -1); + ledger::PublisherInfo publisher(id); publisher.name = info_sql.ColumnString(1); publisher.url = info_sql.ColumnString(2); @@ -412,11 +413,9 @@ bool PublisherInfoDatabase::CreateActivityInfoTable() { "score DOUBLE DEFAULT 0 NOT NULL," "percent INTEGER DEFAULT 0 NOT NULL," "weight DOUBLE DEFAULT 0 NOT NULL," - "month INTEGER NOT NULL," - "year INTEGER NOT NULL," "reconcile_stamp INTEGER DEFAULT 0 NOT NULL," "CONSTRAINT activity_unique " - "UNIQUE (publisher_id, month, year, reconcile_stamp) " + "UNIQUE (publisher_id, reconcile_stamp) " "CONSTRAINT fk_activity_info_publisher_id" " FOREIGN KEY (publisher_id)" " REFERENCES publisher_info (publisher_id)" @@ -452,18 +451,16 @@ bool PublisherInfoDatabase::InsertOrUpdateActivityInfo( GetDB().GetCachedStatement(SQL_FROM_HERE, "INSERT OR REPLACE INTO activity_info " "(publisher_id, duration, score, percent, " - "weight, month, year, reconcile_stamp, visits) " - "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)")); + "weight, reconcile_stamp, visits) " + "VALUES (?, ?, ?, ?, ?, ?, ?)")); activity_info_insert.BindString(0, info.id); activity_info_insert.BindInt64(1, static_cast(info.duration)); activity_info_insert.BindDouble(2, info.score); activity_info_insert.BindInt64(3, static_cast(info.percent)); activity_info_insert.BindDouble(4, info.weight); - activity_info_insert.BindInt(5, info.month); - activity_info_insert.BindInt(6, info.year); - activity_info_insert.BindInt64(7, info.reconcile_stamp); - activity_info_insert.BindInt(8, info.visits); + activity_info_insert.BindInt64(5, info.reconcile_stamp); + activity_info_insert.BindInt(6, info.visits); return activity_info_insert.Run(); } @@ -512,7 +509,7 @@ bool PublisherInfoDatabase::GetActivityList( std::string query = "SELECT ai.publisher_id, ai.duration, ai.score, " "ai.percent, ai.weight, pi.verified, pi.excluded, " - "ai.month, ai.year, pi.name, pi.url, pi.provider, " + "pi.name, pi.url, pi.provider, " "pi.favIcon, ai.reconcile_stamp, ai.visits " "FROM activity_info AS ai " "INNER JOIN publisher_info AS pi " @@ -523,14 +520,6 @@ bool PublisherInfoDatabase::GetActivityList( query += " AND ai.publisher_id = ?"; } - if (filter.month != ledger::ACTIVITY_MONTH::ANY) { - query += " AND ai.month = ?"; - } - - if (filter.year > 0) { - query += " AND ai.year = ?"; - } - if (filter.reconcile_stamp > 0) { query += " AND ai.reconcile_stamp = ?"; } @@ -582,14 +571,6 @@ bool PublisherInfoDatabase::GetActivityList( info_sql.BindString(column++, filter.id); } - if (filter.month != ledger::ACTIVITY_MONTH::ANY) { - info_sql.BindInt(column++, filter.month); - } - - if (filter.year > 0) { - info_sql.BindInt(column++, filter.year); - } - if (filter.reconcile_stamp > 0) { info_sql.BindInt64(column++, filter.reconcile_stamp); } @@ -619,26 +600,21 @@ bool PublisherInfoDatabase::GetActivityList( while (info_sql.Step()) { std::string id(info_sql.ColumnString(0)); - ledger::ACTIVITY_MONTH month( - static_cast(info_sql.ColumnInt(7))); - int year(info_sql.ColumnInt(8)); - ledger::PublisherInfo info(id, month, year); + ledger::PublisherInfo info(id); info.duration = info_sql.ColumnInt64(1); - info.score = info_sql.ColumnDouble(2); info.percent = info_sql.ColumnInt64(3); info.weight = info_sql.ColumnDouble(4); info.verified = info_sql.ColumnBool(5); - info.name = info_sql.ColumnString(9); - info.url = info_sql.ColumnString(10); - info.provider = info_sql.ColumnString(11); - info.favicon_url = info_sql.ColumnString(12); - info.reconcile_stamp = info_sql.ColumnInt64(13); - info.visits = info_sql.ColumnInt(14); - info.excluded = static_cast( info_sql.ColumnInt(6)); + info.name = info_sql.ColumnString(7); + info.url = info_sql.ColumnString(8); + info.provider = info_sql.ColumnString(9); + info.favicon_url = info_sql.ColumnString(10); + info.reconcile_stamp = info_sql.ColumnInt64(11); + info.visits = info_sql.ColumnInt(12); list->push_back(info); } @@ -815,8 +791,7 @@ void PublisherInfoDatabase::GetRecurringDonations( while (info_sql.Step()) { std::string id(info_sql.ColumnString(0)); - ledger::PublisherInfo publisher(id, ledger::ACTIVITY_MONTH::ANY, -1); - + ledger::PublisherInfo publisher(id); publisher.name = info_sql.ColumnString(1); publisher.url = info_sql.ColumnString(2); publisher.favicon_url = info_sql.ColumnString(3); @@ -943,11 +918,19 @@ double PublisherInfoDatabase::GetReservedAmount() { return amount; } -// static + int PublisherInfoDatabase::GetCurrentVersion() { + if (testing_current_version_ != -1) { + return testing_current_version_; + } + return kCurrentVersionNumber; } +void PublisherInfoDatabase::SetTestingCurrentVersion(int value) { + testing_current_version_ = value; +} + void PublisherInfoDatabase::Vacuum() { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); @@ -981,6 +964,10 @@ sql::MetaTable& PublisherInfoDatabase::GetMetaTable() { return meta_table_; } +int PublisherInfoDatabase::GetTableVersionNumber() { + return meta_table_.GetVersionNumber(); +} + // Migration ------------------------------------------------------------------- bool PublisherInfoDatabase::MigrateV1toV2() { @@ -1106,47 +1093,108 @@ bool PublisherInfoDatabase::MigrateV4toV5() { return transaction.Commit(); } -sql::InitStatus PublisherInfoDatabase::EnsureCurrentVersion() { - DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); - - // We can't read databases newer than we were designed for. - if (meta_table_.GetCompatibleVersionNumber() > GetCurrentVersion()) { - LOG(WARNING) << "Publisher info database is too new."; - return sql::INIT_TOO_NEW; +bool PublisherInfoDatabase::MigrateV5toV6() { + sql::Transaction transaction(&GetDB()); + if (!transaction.Begin()) { + return false; } - const int old_version = meta_table_.GetVersionNumber(); - const int cur_version = GetCurrentVersion(); + const char* activity = "activity_info"; + if (GetDB().DoesTableExist(activity)) { + std::string sql = "ALTER TABLE activity_info RENAME TO activity_info_old;"; + + if (!GetDB().Execute(sql.c_str())) { + return false; + } + + if (!CreateActivityInfoTable()) { + return false; + } - // to version 2 - if (old_version < 2 && cur_version < 3) { - if (!MigrateV1toV2()) { - LOG(ERROR) << "DB: Error with MigrateV1toV2"; + if (!CreateActivityInfoIndex()) { + return false; } - } - // to version 3 - if (old_version < 3 && cur_version < 4) { - if (!MigrateV2toV3()) { - LOG(ERROR) << "DB: Error with MigrateV2toV3"; + const std::string columns_insert = "publisher_id, " + "duration, " + "visits, " + "score, " + "percent, " + "weight, " + "reconcile_stamp"; + + const std::string columns_select = "publisher_id, " + "sum(duration) as duration, " + "sum(visits) as duration, " + "sum(score) as score, " + "percent, " + "weight, " + "reconcile_stamp"; + + sql = "PRAGMA foreign_keys=off;"; + sql.append("INSERT INTO activity_info (" + columns_insert + ") " + "SELECT " + columns_select + " " + "FROM activity_info_old " + "GROUP BY publisher_id, reconcile_stamp;"); + sql.append("DROP TABLE activity_info_old;"); + sql.append("PRAGMA foreign_keys=on;"); + + bool result = GetDB().Execute(sql.c_str()); + + if (!result) { + LOG(ERROR) << "DB: Error with MigrateV5toV6"; } } - // to version 4 - if (old_version < 4 && cur_version < 5) { - if (!MigrateV3toV4()) { - LOG(ERROR) << "DB: Error with MigrateV3toV4"; + return transaction.Commit(); +} + +bool PublisherInfoDatabase::Migrate(int version) { + switch (version) { + case 2: { + return MigrateV1toV2(); } + case 3: { + return MigrateV2toV3(); + } + case 4: { + return MigrateV3toV4(); + } + case 5: { + return MigrateV4toV5(); + } + case 6: { + return MigrateV5toV6(); + } + default: + return false; } +} + +sql::InitStatus PublisherInfoDatabase::EnsureCurrentVersion() { + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); - // to version 5 - if (old_version < 5 && cur_version < 6) { - if (!MigrateV4toV5()) { - LOG(ERROR) << "DB: Error with MigrateV4toV5"; + // We can't read databases newer than we were designed for. + if (meta_table_.GetCompatibleVersionNumber() > GetCurrentVersion()) { + LOG(WARNING) << "Publisher info database is too new."; + return sql::INIT_TOO_NEW; + } + + const int old_version = GetTableVersionNumber(); + const int current_version = GetCurrentVersion(); + const int start_version = old_version + 1; + + int migrated_version = old_version; + for (auto i = start_version; i <= current_version; i++) { + if (!Migrate(i)) { + LOG(ERROR) << "DB: Error with MigrateV" << (i - 1) << "toV" << i; + break; } + + migrated_version = i; } - meta_table_.SetVersionNumber(cur_version); + meta_table_.SetVersionNumber(migrated_version); return sql::INIT_OK; } diff --git a/components/brave_rewards/browser/publisher_info_database.h b/components/brave_rewards/browser/publisher_info_database.h index 6632498957e9..e8f54cbf512b 100644 --- a/components/brave_rewards/browser/publisher_info_database.h +++ b/components/brave_rewards/browser/publisher_info_database.h @@ -78,7 +78,9 @@ class PublisherInfoDatabase { // Returns the current version of the publisher info database - static int GetCurrentVersion(); + int GetCurrentVersion(); + + void SetTestingCurrentVersion(int value); // Vacuums the database. This will cause sqlite to defragment and collect // unused space in the file. It can be VERY SLOW. @@ -90,6 +92,8 @@ class PublisherInfoDatabase { bool Init(); + int GetTableVersionNumber(); + private: bool CreateContributionInfoTable(); @@ -123,12 +127,17 @@ class PublisherInfoDatabase { bool MigrateV4toV5(); + bool MigrateV5toV6(); + + bool Migrate(int version); + sql::InitStatus EnsureCurrentVersion(); sql::Database db_; sql::MetaTable meta_table_; const base::FilePath db_path_; bool initialized_; + int testing_current_version_; std::unique_ptr memory_pressure_listener_; diff --git a/components/brave_rewards/browser/publisher_info_database_unittest.cc b/components/brave_rewards/browser/publisher_info_database_unittest.cc index 5fec80bc1653..d6c4e02edaa6 100644 --- a/components/brave_rewards/browser/publisher_info_database_unittest.cc +++ b/components/brave_rewards/browser/publisher_info_database_unittest.cc @@ -4,6 +4,7 @@ #include #include +#include #include "brave/components/brave_rewards/browser/publisher_info_database.h" @@ -49,8 +50,10 @@ class PublisherInfoDatabaseTest : public ::testing::Test { void CreateMigrationDatabase(base::ScopedTempDir* temp_dir, base::FilePath* db_file, - const std::string& version) { - const std::string file_name = "publisher_info_db_v" + version; + int start_version, + int end_version) { + const std::string file_name = "publisher_info_db_v" + + std::to_string(start_version); ASSERT_TRUE(temp_dir->CreateUniqueTempDir()); *db_file = temp_dir->GetPath().AppendASCII(file_name); @@ -71,6 +74,8 @@ class PublisherInfoDatabaseTest : public ::testing::Test { publisher_info_database_ = std::make_unique(*db_file); + + publisher_info_database_->SetTestingCurrentVersion(end_version); ASSERT_NE(publisher_info_database_, nullptr); } @@ -256,8 +261,6 @@ TEST_F(PublisherInfoDatabaseTest, InsertOrUpdateActivityInfo) { info.score = 1.1; info.percent = 100; info.weight = 1.5; - info.month = ledger::ACTIVITY_MONTH::JANUARY; - info.year = 1970; info.reconcile_stamp = 0; info.visits = 1; @@ -277,8 +280,6 @@ TEST_F(PublisherInfoDatabaseTest, InsertOrUpdateActivityInfo) { EXPECT_EQ(info_sql.ColumnDouble(3), info.score); EXPECT_EQ(info_sql.ColumnInt64(4), info.percent); EXPECT_EQ(info_sql.ColumnDouble(5), info.weight); - EXPECT_EQ(info_sql.ColumnInt(6), info.month); - EXPECT_EQ(info_sql.ColumnInt(7), info.year); EXPECT_EQ(static_cast(info_sql.ColumnInt64(8)), info.reconcile_stamp); @@ -300,7 +301,7 @@ TEST_F(PublisherInfoDatabaseTest, InsertOrUpdateActivityInfo) { /** * Make sure that second insert is update and not insert, - * month, year and stamp is unique key + * publisher_id and stamp is unique key */ info.verified = true; info.excluded = ledger::PUBLISHER_EXCLUDE::ALL; @@ -330,11 +331,8 @@ TEST_F(PublisherInfoDatabaseTest, InsertOrUpdateActivityInfo) { EXPECT_EQ(info_sql_1.ColumnDouble(3), info.score); EXPECT_EQ(info_sql_1.ColumnInt64(4), info.percent); EXPECT_EQ(info_sql_1.ColumnDouble(5), info.weight); - EXPECT_EQ(info_sql_1.ColumnInt(6), info.month); - EXPECT_EQ(info_sql_1.ColumnInt(7), info.year); EXPECT_EQ(static_cast(info_sql_1.ColumnInt64(8)), info.reconcile_stamp); - } TEST_F(PublisherInfoDatabaseTest, InsertOrUpdateMediaPublisherInfo) { @@ -497,44 +495,23 @@ TEST_F(PublisherInfoDatabaseTest, GetPanelPublisher) { filter_2.id = "test"; EXPECT_EQ(publisher_info_database_->GetPanelPublisher(filter_2), nullptr); - /** - * Ignore month and year filter - */ - ledger::PublisherInfo info_1; - info_1.id = "brave.com"; - info_1.url = "https://brave.com"; - info_1.percent = 11; - info_1.month = ledger::ACTIVITY_MONTH::JANUARY; - info_1.year = 2019; - info_1.reconcile_stamp = 10; - - bool success = publisher_info_database_->InsertOrUpdateActivityInfo(info_1); - EXPECT_TRUE(success); - - ledger::ActivityInfoFilter filter_3; - filter_3.id = "brave.com"; - filter_3.month = ledger::ACTIVITY_MONTH::ANY; - filter_3.year = -1; - filter_3.reconcile_stamp = 10; - std::unique_ptr result = - publisher_info_database_->GetPanelPublisher(filter_3); - EXPECT_TRUE(result); - EXPECT_EQ(result->id, "brave.com"); - /** * Still get data if reconcile stamp is not found */ + ledger::PublisherInfo info_1; info_1.id = "page.com"; info_1.url = "https://page.com"; + info_1.percent = 11; info_1.reconcile_stamp = 9; - success = publisher_info_database_->InsertOrUpdateActivityInfo(info_1); + bool success = publisher_info_database_->InsertOrUpdateActivityInfo(info_1); EXPECT_TRUE(success); ledger::ActivityInfoFilter filter_4; filter_4.id = "page.com"; filter_4.reconcile_stamp = 10; - result = publisher_info_database_->GetPanelPublisher(filter_4); + std::unique_ptr result = + publisher_info_database_->GetPanelPublisher(filter_4); EXPECT_TRUE(result); EXPECT_EQ(result->id, "page.com"); EXPECT_EQ(result->percent, 0u); @@ -552,16 +529,12 @@ TEST_F(PublisherInfoDatabaseTest, InsertOrUpdateActivityInfos) { info_1.id = "brave.com"; info_1.url = "https://brave.com"; info_1.percent = 11; - info_1.month = ledger::ACTIVITY_MONTH::JANUARY; - info_1.year = 2019; info_1.reconcile_stamp = 10; ledger::PublisherInfo info_2; info_2.id = "clifton.io"; info_2.url = "https://clifton.io"; info_2.percent = 11; - info_2.month = ledger::ACTIVITY_MONTH::JANUARY; - info_2.year = 2019; info_2.reconcile_stamp = 10; ledger::PublisherInfoList list; @@ -587,8 +560,6 @@ TEST_F(PublisherInfoDatabaseTest, InsertOrUpdateActivityInfos) { info_3.id = ""; info_3.url = "https://page.io"; info_3.percent = 11; - info_3.month = ledger::ACTIVITY_MONTH::JANUARY; - info_3.year = 2019; info_3.reconcile_stamp = 10; list.push_back(info_3); @@ -664,8 +635,6 @@ TEST_F(PublisherInfoDatabaseTest, GetActivityList) { info.duration = 0; info.verified = false; info.visits = 0; - info.month = ledger::ACTIVITY_MONTH::JANUARY; - info.year = 1970; info.reconcile_stamp = 1; EXPECT_TRUE(publisher_info_database_->InsertOrUpdateActivityInfo(info)); @@ -780,7 +749,7 @@ TEST_F(PublisherInfoDatabaseTest, GetActivityList) { TEST_F(PublisherInfoDatabaseTest, Migrationv4tov5) { base::ScopedTempDir temp_dir; base::FilePath db_file; - CreateMigrationDatabase(&temp_dir, &db_file, "4"); + CreateMigrationDatabase(&temp_dir, &db_file, 4, 5); ledger::PublisherInfoList list; ledger::ActivityInfoFilter filter; @@ -794,6 +763,66 @@ TEST_F(PublisherInfoDatabaseTest, Migrationv4tov5) { EXPECT_EQ(list.at(1).visits, 1u); EXPECT_EQ(list.at(2).id, "basicattentiontoken.org"); EXPECT_EQ(list.at(2).visits, 3u); + EXPECT_EQ(publisher_info_database_->GetTableVersionNumber(), 5); +} + +TEST_F(PublisherInfoDatabaseTest, Migrationv5tov6) { + base::ScopedTempDir temp_dir; + base::FilePath db_file; + CreateMigrationDatabase(&temp_dir, &db_file, 5, 6); + + ledger::PublisherInfoList list; + ledger::ActivityInfoFilter filter; + filter.excluded = ledger::EXCLUDE_FILTER::FILTER_ALL; + EXPECT_TRUE(publisher_info_database_->GetActivityList(0, 0, filter, &list)); + EXPECT_EQ(static_cast(list.size()), 3); + + EXPECT_EQ(list.at(0).id, "basicattentiontoken.org"); + EXPECT_EQ(list.at(0).duration, 31u); + EXPECT_EQ(list.at(0).visits, 1u); + EXPECT_NEAR(list.at(0).score, 1.1358598545838, 0.001f); + EXPECT_EQ(list.at(0).percent, 26u); + EXPECT_NEAR(list.at(0).weight, 25.919327084376, 0.001f); + EXPECT_EQ(list.at(0).reconcile_stamp, 1553423066u); + EXPECT_EQ(list.at(1).id, "brave.com"); + EXPECT_EQ(list.at(1).duration, 20u); + EXPECT_EQ(list.at(1).visits, 2u); + EXPECT_EQ(list.at(2).id, "slo-tech.com"); + EXPECT_EQ(list.at(2).duration, 44u); + EXPECT_EQ(list.at(2).visits, 2u); + EXPECT_NEAR(list.at(2).score, 2.1717139356, 0.001f); + EXPECT_EQ(list.at(2).percent, 24u); + EXPECT_NEAR(list.at(2).weight, 24.254880708636, 0.001f); + EXPECT_EQ(list.at(2).reconcile_stamp, 1553423066u); + + EXPECT_EQ(publisher_info_database_->GetTableVersionNumber(), 6); +} + +TEST_F(PublisherInfoDatabaseTest, Migrationv4tov6) { + base::ScopedTempDir temp_dir; + base::FilePath db_file; + CreateMigrationDatabase(&temp_dir, &db_file, 4, 6); + + ledger::PublisherInfoList list; + ledger::ActivityInfoFilter filter; + filter.excluded = ledger::EXCLUDE_FILTER::FILTER_ALL; + EXPECT_TRUE(publisher_info_database_->GetActivityList(0, 0, filter, &list)); + EXPECT_EQ(static_cast(list.size()), 3); + + EXPECT_EQ(list.at(0).id, "basicattentiontoken.org"); + EXPECT_EQ(list.at(0).duration, 15u); + EXPECT_EQ(list.at(0).visits, 3u); + EXPECT_EQ(list.at(0).reconcile_stamp, 1552214829u); + EXPECT_EQ(list.at(1).id, "brave.com"); + EXPECT_EQ(list.at(1).duration, 10u); + EXPECT_EQ(list.at(1).visits, 1u); + EXPECT_EQ(list.at(1).reconcile_stamp, 1552214829u); + EXPECT_EQ(list.at(2).id, "slo-tech.com"); + EXPECT_EQ(list.at(2).duration, 12u); + EXPECT_EQ(list.at(2).visits, 1u); + EXPECT_EQ(list.at(2).reconcile_stamp, 1552214829u); + + EXPECT_EQ(publisher_info_database_->GetTableVersionNumber(), 6); } } // namespace brave_rewards diff --git a/components/brave_rewards/browser/rewards_service_impl.cc b/components/brave_rewards/browser/rewards_service_impl.cc index 49a1c9c92d17..5f4990d4a26c 100644 --- a/components/brave_rewards/browser/rewards_service_impl.cc +++ b/components/brave_rewards/browser/rewards_service_impl.cc @@ -475,8 +475,6 @@ void RewardsServiceImpl::GetContentSiteList( uint32_t min_visits, const GetContentSiteListCallback& callback) { ledger::ActivityInfoFilter filter; - filter.month = ledger::ACTIVITY_MONTH::ANY; - filter.year = -1; filter.min_duration = min_visit_time; filter.order_by.push_back(std::pair("ai.percent", false)); filter.reconcile_stamp = reconcile_stamp; @@ -518,13 +516,10 @@ void RewardsServiceImpl::OnLoad(SessionID tab_id, const GURL& url) { const std::string publisher_url = origin.scheme() + "://" + baseDomain + "/"; - auto now = base::Time::Now(); ledger::VisitData data(baseDomain, origin.host(), url.path(), tab_id.id(), - GetPublisherMonth(now), - GetPublisherYear(now), baseDomain, publisher_url, "", @@ -601,18 +596,14 @@ void RewardsServiceImpl::OnPostData(SessionID tab_id, if (output.empty()) return; - auto now = base::Time::Now(); - ledger::VisitData visit_data( - "", - "", - url.spec(), - tab_id.id(), - GetPublisherMonth(now), - GetPublisherYear(now), - "", - "", - "", - ""); + ledger::VisitData visit_data(std::string(), + std::string(), + url.spec(), + tab_id.id(), + std::string(), + std::string(), + std::string(), + std::string()); bat_ledger_->OnPostData(url.spec(), first_party_url.spec(), @@ -634,17 +625,21 @@ void RewardsServiceImpl::OnXHRLoad(SessionID tab_id, parts[it.GetKey()] = it.GetUnescapedValue(); } - auto now = base::Time::Now(); - ledger::VisitData data("", "", url.spec(), tab_id.id(), - GetPublisherMonth(now), GetPublisherYear(now), - "", "", "", ""); + ledger::VisitData data(std::string(), + std::string(), + url.spec(), + tab_id.id(), + std::string(), + std::string(), + std::string(), + std::string()); bat_ledger_->OnXHRLoad(tab_id.id(), - url.spec(), - mojo::MapToFlatMap(parts), - first_party_url.spec(), - referrer.spec(), - data.ToJson()); + url.spec(), + mojo::MapToFlatMap(parts), + first_party_url.spec(), + referrer.spec(), + data.ToJson()); } void RewardsServiceImpl::LoadPublisherInfo( @@ -1782,7 +1777,6 @@ void RewardsServiceImpl::GetPublisherActivityFromUrl( return; } - auto now = base::Time::Now(); auto origin = parsedUrl.GetOrigin(); std::string baseDomain = GetDomainAndRegistry(origin.host(), INCLUDE_PRIVATE_REGISTRIES); @@ -1799,8 +1793,6 @@ void RewardsServiceImpl::GetPublisherActivityFromUrl( ledger::VisitData visitData; visitData.domain = baseDomain; visitData.path = parsedUrl.PathForRequest(); - visitData.local_month = GetPublisherMonth(now); - visitData.local_year = GetPublisherYear(now); visitData.name = baseDomain; visitData.url = origin.spec(); visitData.favicon_url = favicon_url; @@ -1998,10 +1990,7 @@ void RewardsServiceImpl::OnDonate(const std::string& publisher_key, int amount, if (!Connected()) return; - ledger::PublisherInfo publisher( - publisher_key, - ledger::ACTIVITY_MONTH::ANY, - -1); + ledger::PublisherInfo publisher(publisher_key); bat_ledger_->DoDirectDonation(publisher.ToJson(), amount, "BAT"); } @@ -2398,8 +2387,6 @@ void RewardsServiceImpl::OnDonate( ledger::PublisherInfo info; info.id = publisher_key; - info.month = ledger::ACTIVITY_MONTH::ANY; - info.year = -1; info.verified = site->verified; info.excluded = ledger::PUBLISHER_EXCLUDE::DEFAULT; info.name = site->name; diff --git a/test/data/rewards-data/migration/publisher_info_db_v5 b/test/data/rewards-data/migration/publisher_info_db_v5 new file mode 100644 index 000000000000..a703b4a39ff1 Binary files /dev/null and b/test/data/rewards-data/migration/publisher_info_db_v5 differ diff --git a/vendor/bat-native-ledger/include/bat/ledger/ledger.h b/vendor/bat-native-ledger/include/bat/ledger/ledger.h index 9193ed6e4ad9..389eb3ec50f2 100644 --- a/vendor/bat-native-ledger/include/bat/ledger/ledger.h +++ b/vendor/bat-native-ledger/include/bat/ledger/ledger.h @@ -30,8 +30,6 @@ LEDGER_EXPORT struct VisitData { const std::string& _domain, const std::string& _path, uint32_t _tab_id, - ACTIVITY_MONTH _local_month, - int _local_year, const std::string& name, const std::string& url, const std::string& provider, @@ -46,8 +44,6 @@ LEDGER_EXPORT struct VisitData { std::string domain; std::string path; uint32_t tab_id; - ACTIVITY_MONTH local_month; - int local_year; std::string name; std::string url; std::string provider; diff --git a/vendor/bat-native-ledger/include/bat/ledger/publisher_info.h b/vendor/bat-native-ledger/include/bat/ledger/publisher_info.h index 55b38c37a18b..71271aef0078 100644 --- a/vendor/bat-native-ledger/include/bat/ledger/publisher_info.h +++ b/vendor/bat-native-ledger/include/bat/ledger/publisher_info.h @@ -65,8 +65,6 @@ LEDGER_EXPORT struct ActivityInfoFilter { bool loadFromJson(const std::string& json); std::string id; - ACTIVITY_MONTH month; - int year; EXCLUDE_FILTER excluded; uint32_t percent; std::vector> order_by; @@ -112,9 +110,7 @@ LEDGER_EXPORT struct PublisherBanner { LEDGER_EXPORT struct PublisherInfo { PublisherInfo(); - PublisherInfo(const std::string& publisher_id, - ACTIVITY_MONTH month, - int year); + PublisherInfo(const std::string& publisher_id); PublisherInfo(const PublisherInfo& info); ~PublisherInfo(); @@ -132,8 +128,6 @@ LEDGER_EXPORT struct PublisherInfo { double weight; PUBLISHER_EXCLUDE excluded; REWARDS_CATEGORY category; - ACTIVITY_MONTH month; - int year; uint64_t reconcile_stamp; bool verified; std::string name; diff --git a/vendor/bat-native-ledger/src/bat/ledger/ledger.cc b/vendor/bat-native-ledger/src/bat/ledger/ledger.cc index 48b4239f99f5..8e40ad5137b1 100644 --- a/vendor/bat-native-ledger/src/bat/ledger/ledger.cc +++ b/vendor/bat-native-ledger/src/bat/ledger/ledger.cc @@ -26,8 +26,6 @@ VisitData::VisitData(const std::string& _tld, const std::string& _domain, const std::string& _path, uint32_t _tab_id, - ACTIVITY_MONTH _local_month, - int _local_year, const std::string& _name, const std::string& _url, const std::string& _provider, @@ -36,8 +34,6 @@ VisitData::VisitData(const std::string& _tld, domain(_domain), path(_path), tab_id(_tab_id), - local_month(_local_month), - local_year(_local_year), name(_name), url(_url), provider(_provider), @@ -48,8 +44,6 @@ VisitData::VisitData(const VisitData& data) : domain(data.domain), path(data.path), tab_id(data.tab_id), - local_month(data.local_month), - local_year(data.local_year), name(data.name), url(data.url), provider(data.provider), @@ -74,8 +68,6 @@ bool VisitData::loadFromJson(const std::string& json) { d.HasMember("domain") && d["domain"].IsString() && d.HasMember("path") && d["path"].IsString() && d.HasMember("tab_id") && d["tab_id"].IsUint() && - d.HasMember("local_month") && d["local_month"].IsInt() && - d.HasMember("local_year") && d["local_year"].IsInt() && d.HasMember("name") && d["name"].IsString() && d.HasMember("url") && d["url"].IsString() && d.HasMember("provider") && d["provider"].IsString() && @@ -87,8 +79,6 @@ bool VisitData::loadFromJson(const std::string& json) { domain = d["domain"].GetString(); path = d["path"].GetString(); tab_id = d["tab_id"].GetUint(); - local_month = (ACTIVITY_MONTH)d["local_month"].GetInt(); - local_year = d["local_year"].GetInt(); name = d["name"].GetString(); url = d["url"].GetString(); provider = d["provider"].GetString(); @@ -100,8 +90,6 @@ bool VisitData::loadFromJson(const std::string& json) { ActivityInfoFilter::ActivityInfoFilter() : - month(ACTIVITY_MONTH::ANY), - year(-1), excluded(EXCLUDE_FILTER::FILTER_DEFAULT), percent(0), min_duration(0), @@ -111,8 +99,6 @@ ActivityInfoFilter::ActivityInfoFilter() : ActivityInfoFilter::ActivityInfoFilter(const ActivityInfoFilter& filter) : id(filter.id), - month(filter.month), - year(filter.year), excluded(filter.excluded), percent(filter.percent), order_by(filter.order_by), @@ -137,8 +123,6 @@ bool ActivityInfoFilter::loadFromJson(const std::string& json) { bool error = d.HasParseError(); if (false == error) { error = !(d.HasMember("id") && d["id"].IsString() && - d.HasMember("month") && d["month"].IsInt() && - d.HasMember("year") && d["year"].IsInt() && d.HasMember("excluded") && d["excluded"].IsInt() && d.HasMember("percent") && d["percent"].IsUint() && d.HasMember("order_by") && d["order_by"].IsObject() && @@ -149,8 +133,6 @@ bool ActivityInfoFilter::loadFromJson(const std::string& json) { if (false == error) { id = d["id"].GetString(); - month = (ACTIVITY_MONTH)d["month"].GetInt(); - year = d["year"].GetInt(); excluded = (EXCLUDE_FILTER)d["excluded"].GetInt(); percent = d["percent"].GetUint(); min_duration = d["min_duration"].GetUint64(); @@ -246,8 +228,6 @@ PublisherInfo::PublisherInfo() : weight(.0), excluded(PUBLISHER_EXCLUDE::DEFAULT), category(REWARDS_CATEGORY::AUTO_CONTRIBUTE), - month(ACTIVITY_MONTH::ANY), - year(-1), reconcile_stamp(0), verified(false), name(""), @@ -255,9 +235,7 @@ PublisherInfo::PublisherInfo() : provider(""), favicon_url("") {} -PublisherInfo::PublisherInfo(const std::string& publisher_id, - ACTIVITY_MONTH _month, - int _year) : +PublisherInfo::PublisherInfo(const std::string& publisher_id) : id(publisher_id), duration(0u), score(.0), @@ -266,8 +244,6 @@ PublisherInfo::PublisherInfo(const std::string& publisher_id, weight(.0), excluded(PUBLISHER_EXCLUDE::DEFAULT), category(REWARDS_CATEGORY::AUTO_CONTRIBUTE), - month(_month), - year(_year), reconcile_stamp(0), verified(false), name(""), @@ -284,8 +260,6 @@ PublisherInfo::PublisherInfo(const PublisherInfo& info) : weight(info.weight), excluded(info.excluded), category(info.category), - month(info.month), - year(info.year), reconcile_stamp(info.reconcile_stamp), verified(info.verified), name(info.name), @@ -301,7 +275,7 @@ bool PublisherInfo::operator<(const PublisherInfo& rhs) const { } bool PublisherInfo::is_valid() const { - return !id.empty() && year > 0 && month != ACTIVITY_MONTH::ANY; + return !id.empty(); } const std::string PublisherInfo::ToJson() const { @@ -325,8 +299,6 @@ bool PublisherInfo::loadFromJson(const std::string& json) { d.HasMember("weight") && d["weight"].IsDouble() && d.HasMember("excluded") && d["excluded"].IsInt() && d.HasMember("category") && d["category"].IsInt() && - d.HasMember("month") && d["month"].IsInt() && - d.HasMember("year") && d["year"].IsInt() && d.HasMember("reconcile_stamp") && d["reconcile_stamp"].IsUint64() && d.HasMember("verified") && d["verified"].IsBool() && d.HasMember("name") && d["name"].IsString() && @@ -345,8 +317,6 @@ bool PublisherInfo::loadFromJson(const std::string& json) { weight = d["weight"].GetDouble(); excluded = (PUBLISHER_EXCLUDE)d["excluded"].GetInt(); category = (REWARDS_CATEGORY)d["category"].GetInt(); - month = (ACTIVITY_MONTH)d["month"].GetInt(); - year = d["year"].GetInt(); reconcile_stamp = d["reconcile_stamp"].GetUint64(); verified = d["verified"].GetBool(); name = d["name"].GetString(); @@ -368,7 +338,7 @@ bool PublisherInfo::loadFromJson(const std::string& json) { return !error; } -const PublisherInfo invalid("", ACTIVITY_MONTH::ANY, -1); +const PublisherInfo invalid(""); const std::string ContributionInfo::ToJson() const { std::string json; diff --git a/vendor/bat-native-ledger/src/bat_contribution.cc b/vendor/bat-native-ledger/src/bat_contribution.cc index 17c54c2f43c0..bf20b6c23de0 100644 --- a/vendor/bat-native-ledger/src/bat_contribution.cc +++ b/vendor/bat-native-ledger/src/bat_contribution.cc @@ -234,8 +234,6 @@ void BatContribution::StartAutoContribute() { uint64_t current_reconcile_stamp = ledger_->GetReconcileStamp(); ledger::ActivityInfoFilter filter = ledger_->CreateActivityFilter( "", - ledger::ACTIVITY_MONTH::ANY, - -1, ledger::EXCLUDE_FILTER::FILTER_ALL_EXCEPT_EXCLUDED, true, current_reconcile_stamp, diff --git a/vendor/bat-native-ledger/src/bat_get_media.cc b/vendor/bat-native-ledger/src/bat_get_media.cc index 8cb5ef5b41a0..92ff579678ba 100644 --- a/vendor/bat-native-ledger/src/bat_get_media.cc +++ b/vendor/bat-native-ledger/src/bat_get_media.cc @@ -495,8 +495,6 @@ void BatGetMedia::onMediaActivityError(const ledger::VisitData& visit_data, if (!url.empty()) { ledger::VisitData new_data; - new_data.local_month = visit_data.local_month; - new_data.local_year = visit_data.local_year; new_data.domain = url; new_data.url = "https://" + url; new_data.path = "/"; @@ -687,19 +685,17 @@ void BatGetMedia::fetchPublisherDataFromDB( const std::string& publisher_key, const std::string& publisher_blob, const bool is_custom_path) { - auto filter = ledger_->CreateActivityFilter( - publisher_key, - ledger::ACTIVITY_MONTH::ANY, - -1, - ledger::EXCLUDE_FILTER::FILTER_ALL, - false, - ledger_->GetReconcileStamp(), - true, - false); - ledger_->GetPanelPublisherInfo(filter, - std::bind(&BatGetMedia::onFetchPublisherFromDBResponse, - this, _1, _2, windowId, visit_data, providerType, - publisher_key, publisher_blob, is_custom_path)); + auto filter = ledger_->CreateActivityFilter( + publisher_key, + ledger::EXCLUDE_FILTER::FILTER_ALL, + false, + ledger_->GetReconcileStamp(), + true, + false); + ledger_->GetPanelPublisherInfo(filter, + std::bind(&BatGetMedia::onFetchPublisherFromDBResponse, + this, _1, _2, windowId, visit_data, providerType, + publisher_key, publisher_blob, is_custom_path)); } void BatGetMedia::onFetchPublisherFromDBResponse( diff --git a/vendor/bat-native-ledger/src/bat_helper.cc b/vendor/bat-native-ledger/src/bat_helper.cc index 78cc1a6c0cc2..510446ab3719 100644 --- a/vendor/bat-native-ledger/src/bat_helper.cc +++ b/vendor/bat-native-ledger/src/bat_helper.cc @@ -2724,12 +2724,6 @@ void saveToJson(JsonWriter& writer, const ledger::VisitData& visitData) { writer.String("tab_id"); writer.Uint(visitData.tab_id); - writer.String("local_month"); - writer.Int(visitData.local_month); - - writer.String("local_year"); - writer.Int(visitData.local_year); - writer.String("name"); writer.String(visitData.name.c_str()); @@ -2826,12 +2820,6 @@ void saveToJson(JsonWriter & writer, const ledger::PublisherInfo& info) { writer.String("category"); writer.Int(info.category); - writer.String("month"); - writer.Int(info.month); - - writer.String("year"); - writer.Int(info.year); - writer.String("reconcile_stamp"); writer.Uint64(info.reconcile_stamp); @@ -2928,12 +2916,6 @@ void saveToJson(JsonWriter & writer, writer.String("id"); writer.String(info.id.c_str()); - writer.String("month"); - writer.Int(info.month); - - writer.String("year"); - writer.Int(info.year); - writer.String("excluded"); writer.Int(info.excluded); diff --git a/vendor/bat-native-ledger/src/bat_publishers.cc b/vendor/bat-native-ledger/src/bat_publishers.cc index f2863b9c7eff..c38f0cce06fe 100644 --- a/vendor/bat-native-ledger/src/bat_publishers.cc +++ b/vendor/bat-native-ledger/src/bat_publishers.cc @@ -90,8 +90,6 @@ void BatPublishers::saveVisit(const std::string& publisher_id, } auto filter = CreateActivityFilter(publisher_id, - ledger::ACTIVITY_MONTH::ANY, - -1, ledger::EXCLUDE_FILTER::FILTER_ALL, false, ledger_->GetReconcileStamp(), @@ -109,54 +107,8 @@ void BatPublishers::saveVisit(const std::string& publisher_id, ledger_->GetActivityInfo(filter, callbackGetPublishers); } -ledger::ActivityInfoFilter BatPublishers::CreateActivityFilter( - const std::string &publisher_id, - ledger::ACTIVITY_MONTH month, - int year) { - return CreateActivityFilter(publisher_id, - month, - year, - ledger::EXCLUDE_FILTER::FILTER_ALL, - true, - 0, - true, - false); -} - -ledger::ActivityInfoFilter BatPublishers::CreateActivityFilter( - const std::string& publisher_id, - ledger::ACTIVITY_MONTH month, - int year, - ledger::EXCLUDE_FILTER excluded) { - return CreateActivityFilter(publisher_id, - month, - year, - excluded, - true, - 0, - true, - false); -} - -ledger::ActivityInfoFilter BatPublishers::CreateActivityFilter( - const std::string &publisher_id, - ledger::ACTIVITY_MONTH month, - int year, - bool min_duration) { - return CreateActivityFilter(publisher_id, - month, - year, - ledger::EXCLUDE_FILTER::FILTER_ALL, - min_duration, - 0, - true, - false); -} - ledger::ActivityInfoFilter BatPublishers::CreateActivityFilter( const std::string& publisher_id, - ledger::ACTIVITY_MONTH month, - int year, ledger::EXCLUDE_FILTER excluded, bool min_duration, const uint64_t& currentReconcileStamp, @@ -164,8 +116,6 @@ ledger::ActivityInfoFilter BatPublishers::CreateActivityFilter( bool min_visits) { ledger::ActivityInfoFilter filter; filter.id = publisher_id; - filter.month = month; - filter.year = year; filter.excluded = excluded; filter.min_duration = min_duration ? getPublisherMinVisitTime() : 0; filter.reconcile_stamp = currentReconcileStamp; @@ -207,9 +157,7 @@ void BatPublishers::saveVisitInternal( bool new_visit = false; if (!publisher_info.get()) { new_visit = true; - publisher_info.reset(new ledger::PublisherInfo(publisher_id, - visit_data.local_month, - visit_data.local_year)); + publisher_info.reset(new ledger::PublisherInfo(publisher_id)); } std::string fav_icon = visit_data.favicon_url; @@ -595,8 +543,6 @@ void BatPublishers::synopsisNormalizerInternal( void BatPublishers::SynopsisNormalizer() { auto filter = CreateActivityFilter("", - ledger::ACTIVITY_MONTH::ANY, - -1, ledger::EXCLUDE_FILTER::FILTER_ALL_EXCEPT_EXCLUDED, true, ledger_->GetReconcileStamp(), @@ -832,8 +778,6 @@ void BatPublishers::getPublisherActivityFromUrl( } auto filter = CreateActivityFilter(visit_data.domain, - ledger::ACTIVITY_MONTH::ANY, - -1, ledger::EXCLUDE_FILTER::FILTER_ALL, false, ledger_->GetReconcileStamp(), @@ -843,8 +787,6 @@ void BatPublishers::getPublisherActivityFromUrl( ledger::VisitData new_data; new_data.domain = visit_data.domain; new_data.path = visit_data.path; - new_data.local_month = visit_data.local_month; - new_data.local_year = visit_data.local_year; new_data.name = visit_data.name; new_data.url = visit_data.url; new_data.favicon_url = ""; diff --git a/vendor/bat-native-ledger/src/bat_publishers.h b/vendor/bat-native-ledger/src/bat_publishers.h index d6991948aa41..d87922e0c2db 100644 --- a/vendor/bat-native-ledger/src/bat_publishers.h +++ b/vendor/bat-native-ledger/src/bat_publishers.h @@ -116,25 +116,6 @@ class BatPublishers : public ledger::LedgerCallbackHandler { ledger::ActivityInfoFilter CreateActivityFilter( const std::string& publisher_id, - ledger::ACTIVITY_MONTH month, - int year); - - ledger::ActivityInfoFilter CreateActivityFilter( - const std::string& publisher_id, - ledger::ACTIVITY_MONTH month, - int year, - ledger::EXCLUDE_FILTER excluded); - - ledger::ActivityInfoFilter CreateActivityFilter( - const std::string& publisher_id, - ledger::ACTIVITY_MONTH month, - int year, - bool min_duration); - - ledger::ActivityInfoFilter CreateActivityFilter( - const std::string& publisher_id, - ledger::ACTIVITY_MONTH month, - int year, ledger::EXCLUDE_FILTER excluded, bool min_duration, const uint64_t& currentReconcileStamp, diff --git a/vendor/bat-native-ledger/src/ledger_impl.cc b/vendor/bat-native-ledger/src/ledger_impl.cc index 86dc9ecdccc4..d8c7d607c7ee 100644 --- a/vendor/bat-native-ledger/src/ledger_impl.cc +++ b/vendor/bat-native-ledger/src/ledger_impl.cc @@ -963,16 +963,12 @@ void LedgerImpl::OnRemovedRecurring(ledger::Result result) { ledger::ActivityInfoFilter LedgerImpl::CreateActivityFilter( const std::string& publisher_id, - ledger::ACTIVITY_MONTH month, - int year, ledger::EXCLUDE_FILTER excluded, bool min_duration, const uint64_t& currentReconcileStamp, bool non_verified, bool min_visits) { return bat_publishers_->CreateActivityFilter(publisher_id, - month, - year, excluded, min_duration, currentReconcileStamp, diff --git a/vendor/bat-native-ledger/src/ledger_impl.h b/vendor/bat-native-ledger/src/ledger_impl.h index 67688de97981..030647da3483 100644 --- a/vendor/bat-native-ledger/src/ledger_impl.h +++ b/vendor/bat-native-ledger/src/ledger_impl.h @@ -294,8 +294,6 @@ class LedgerImpl : public ledger::Ledger, ledger::ActivityInfoFilter CreateActivityFilter( const std::string& publisher_id, - ledger::ACTIVITY_MONTH month, - int year, ledger::EXCLUDE_FILTER excluded, bool min_duration, const uint64_t& currentReconcileStamp,