Add TimerCreators
This commit is contained in:
parent
ebc16986e8
commit
cb500fd67c
7 changed files with 41 additions and 2 deletions
|
@ -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::market_list> TimerShops;
|
||||||
typedef TimerOroApi<&oro::Api::items_list> TimerItems;
|
typedef TimerOroApi<&oro::Api::items_list> TimerItems;
|
||||||
typedef TimerOroApi<&oro::Api::items_icons> TimerIcons;
|
typedef TimerOroApi<&oro::Api::items_icons> TimerIcons;
|
||||||
|
typedef TimerOroApi<&oro::Api::fame_list> TimerCreators;
|
||||||
|
|
||||||
std::cout << "Running with " << thread_count << " worker threads\n";
|
std::cout << "Running with " << thread_count << " worker threads\n";
|
||||||
roar11::ThreadPool pool(thread_count);
|
roar11::ThreadPool pool(thread_count);
|
||||||
|
|
|
@ -108,7 +108,7 @@ BOOST_FUSION_ADAPT_STRUCT(
|
||||||
|
|
||||||
BOOST_FUSION_ADAPT_STRUCT(
|
BOOST_FUSION_ADAPT_STRUCT(
|
||||||
oro::Creator,
|
oro::Creator,
|
||||||
(unsigned int, id)
|
(unsigned int, char_id)
|
||||||
(std::string, name)
|
(std::string, name)
|
||||||
(unsigned int, points)
|
(unsigned int, points)
|
||||||
)
|
)
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
|
|
||||||
namespace oro {
|
namespace oro {
|
||||||
struct Creator {
|
struct Creator {
|
||||||
unsigned int id;
|
unsigned int char_id;
|
||||||
std::string name;
|
std::string name;
|
||||||
unsigned int points;
|
unsigned int points;
|
||||||
};
|
};
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#include "oro/items.hpp"
|
#include "oro/items.hpp"
|
||||||
#include "oro/icons.hpp"
|
#include "oro/icons.hpp"
|
||||||
#include "oro/shops.hpp"
|
#include "oro/shops.hpp"
|
||||||
|
#include "oro/creators.hpp"
|
||||||
#include "oro/dateconv.hpp"
|
#include "oro/dateconv.hpp"
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
@ -273,4 +274,34 @@ void OriginsDB::update (const Shops& shops) {
|
||||||
transaction.commit();
|
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
|
} //namespace oro
|
||||||
|
|
|
@ -36,6 +36,7 @@ public:
|
||||||
void update (const Items& items);
|
void update (const Items& items);
|
||||||
void update (const Icons& icons);
|
void update (const Icons& icons);
|
||||||
void update (const Shops& shops);
|
void update (const Shops& shops);
|
||||||
|
void update (const Creators& creat);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string m_path;
|
std::string m_path;
|
||||||
|
|
|
@ -77,4 +77,8 @@ void TimerBase::update_db (const oro::Icons& icons) {
|
||||||
db().update(icons);
|
db().update(icons);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TimerBase::update_db (const oro::Creators& creators) {
|
||||||
|
db().update(creators);
|
||||||
|
}
|
||||||
|
|
||||||
} //namespace duck
|
} //namespace duck
|
||||||
|
|
|
@ -31,6 +31,7 @@ namespace oro {
|
||||||
struct Shops;
|
struct Shops;
|
||||||
struct Icons;
|
struct Icons;
|
||||||
struct Items;
|
struct Items;
|
||||||
|
struct Creators;
|
||||||
} //namespace oro
|
} //namespace oro
|
||||||
|
|
||||||
namespace duck {
|
namespace duck {
|
||||||
|
@ -53,6 +54,7 @@ protected:
|
||||||
void update_db (const oro::Shops& shops);
|
void update_db (const oro::Shops& shops);
|
||||||
void update_db (const oro::Items& items);
|
void update_db (const oro::Items& items);
|
||||||
void update_db (const oro::Icons& icons);
|
void update_db (const oro::Icons& icons);
|
||||||
|
void update_db (const oro::Creators& creators);
|
||||||
roar11::ThreadPool& pool();
|
roar11::ThreadPool& pool();
|
||||||
oro::Api& oro_api();
|
oro::Api& oro_api();
|
||||||
oro::OriginsDB& db();
|
oro::OriginsDB& db();
|
||||||
|
|
Loading…
Add table
Reference in a new issue