Add TimerCreators

This commit is contained in:
King_DuckZ 2020-08-11 02:10:43 +01:00
parent ebc16986e8
commit cb500fd67c
7 changed files with 41 additions and 2 deletions

View file

@ -47,6 +47,7 @@ void test(oro::Api* api, oro::OriginsDB* db, std::size_t thread_count) {
typedef TimerOroApi<&oro::Api::market_list> TimerShops;
typedef TimerOroApi<&oro::Api::items_list> TimerItems;
typedef TimerOroApi<&oro::Api::items_icons> TimerIcons;
typedef TimerOroApi<&oro::Api::fame_list> TimerCreators;
std::cout << "Running with " << thread_count << " worker threads\n";
roar11::ThreadPool pool(thread_count);

View file

@ -108,7 +108,7 @@ BOOST_FUSION_ADAPT_STRUCT(
BOOST_FUSION_ADAPT_STRUCT(
oro::Creator,
(unsigned int, id)
(unsigned int, char_id)
(std::string, name)
(unsigned int, points)
)

View file

@ -23,7 +23,7 @@
namespace oro {
struct Creator {
unsigned int id;
unsigned int char_id;
std::string name;
unsigned int points;
};

View file

@ -23,6 +23,7 @@
#include "oro/items.hpp"
#include "oro/icons.hpp"
#include "oro/shops.hpp"
#include "oro/creators.hpp"
#include "oro/dateconv.hpp"
#include <mutex>
#include <optional>
@ -273,4 +274,34 @@ void OriginsDB::update (const Shops& shops) {
transaction.commit();
}
void OriginsDB::update (const Creators& creat) {
Database db(m_db_mutex, m_path);
db.exec("CREATE TABLE IF NOT EXISTS fame_list("
"id INTEGER PRIMARY KEY NOT NULL"
", type TINYINT"
", master_id INTEGER UNIQUE"
", name TEXT"
", points INTEGER"
")"
);
auto insert_creators = [](SQLite::Statement& query, const std::vector<oro::Creator>& creats, int type) {
for (const auto& creator : creats) {
query.bind(1, type);
query.bind(2, creator.char_id);
query.bind(3, creator.name);
query.bind(4, creator.points);
query.exec();
query.reset();
}
};
SQLite::Statement query(db, "INSERT INTO fame_list(type, master_id, name, points) VALUES (?, ?, ?, ?) ON CONFLICT(master_id) DO UPDATE SET points=excluded.points");
SQLite::Transaction transaction(db);
insert_creators(query, creat.brewers, 1);
insert_creators(query, creat.forgers, 2);
transaction.commit();
}
} //namespace oro

View file

@ -36,6 +36,7 @@ public:
void update (const Items& items);
void update (const Icons& icons);
void update (const Shops& shops);
void update (const Creators& creat);
private:
std::string m_path;

View file

@ -77,4 +77,8 @@ void TimerBase::update_db (const oro::Icons& icons) {
db().update(icons);
}
void TimerBase::update_db (const oro::Creators& creators) {
db().update(creators);
}
} //namespace duck

View file

@ -31,6 +31,7 @@ namespace oro {
struct Shops;
struct Icons;
struct Items;
struct Creators;
} //namespace oro
namespace duck {
@ -53,6 +54,7 @@ protected:
void update_db (const oro::Shops& shops);
void update_db (const oro::Items& items);
void update_db (const oro::Icons& icons);
void update_db (const oro::Creators& creators);
roar11::ThreadPool& pool();
oro::Api& oro_api();
oro::OriginsDB& db();