Update last_seen in shop snapshot table

This commit is contained in:
King_DuckZ 2020-08-15 02:49:03 +01:00
parent ce892691f3
commit 1b65162a18

View file

@ -392,22 +392,34 @@ void OriginsDB::update (const Shops& shops) {
SQLite::Statement sel_sshot(db, "SELECT id FROM shop_snapshots WHERE shop_id = ? AND hash = ?");
SQLite::Statement ins_item(db, "INSERT INTO shop_items(snapshot_id, item_id, amount, price, refine, star_crumbs, element, creator, beloved) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?)");
SQLite::Statement ins_card(db, "INSERT INTO slotted_cards(shop_item_id, card_id) VALUES(?, ?)");
SQLite::Statement upd_snapshot_date(db, "UPDATE shop_snapshots SET last_seen_date=CURRENT_TIMESTAMP WHERE id=?");
InsertShopIfn insert_shop_ifn(db);
ItemIdToTableId item_id_to_table_id(db);
SQLite::Transaction transaction(db);
for (const auto& shop : shops.shops) {
{
//insert new shop or get its id if already there
const auto shop_id_ins = insert_shop_ifn(shop);
auto sshot_id_ins = exec_first_res<SQLiteID>(sel_sshot, shop_id_ins.first, shop_hash(shop));
if (sshot_id_ins)
std::string hash(shop_hash(shop));
//get snapshot hash if already there
const auto sshot_id_opt = exec_first_res<SQLiteID>(sel_sshot, shop_id_ins.first, no_copy(hash));
if (sshot_id_opt) {
//already there, update last seen date and move on
bind(upd_snapshot_date, 1, *sshot_id_opt);
upd_snapshot_date.exec();
upd_snapshot_date.reset();
continue;
}
bind_all(ins_sshot, shop_id_ins.first, shop_hash(shop));
//snapshot is new, insert it
bind_all(ins_sshot, shop_id_ins.first, no_copy(hash));
ins_sshot.exec();
ins_sshot.reset();
}
//insert items relative to this snapshot and associated slotted cards
const auto sshot_id = db.getLastInsertRowid();
for (const auto& item : shop.items) {
bind_all(ins_item, sshot_id, item_id_to_table_id(item.item_id),