drastically improve performance for loading sales
This commit is contained in:
parent
8f5797bbfb
commit
56931c2e27
1 changed files with 23 additions and 25 deletions
|
@ -608,6 +608,7 @@ unsigned int Database::loadSales(std::vector<std::unique_ptr<Sale>>& sales,
|
|||
|
||||
sales.clear();
|
||||
|
||||
std::map<std::string, Sale*> saleMap;
|
||||
while (retCode != SQLITE_DONE) {
|
||||
++count;
|
||||
auto sale = std::make_unique<Sale>();
|
||||
|
@ -615,6 +616,7 @@ unsigned int Database::loadSales(std::vector<std::unique_ptr<Sale>>& sales,
|
|||
sale->setSourceNo(sqlite3_column_int(stmt, 1));
|
||||
sale->setTimestamp(reinterpret_cast<const char*>(sqlite3_column_text(stmt, 2)));
|
||||
sale->setState(Sale::State::OK);
|
||||
saleMap.insert(std::make_pair(sale->getUuidAsString(), sale.get()));
|
||||
sales.push_back(std::move(sale));
|
||||
|
||||
retCode = sqlite3_step(stmt);
|
||||
|
@ -622,35 +624,31 @@ unsigned int Database::loadSales(std::vector<std::unique_ptr<Sale>>& sales,
|
|||
|
||||
sqlite3_finalize(stmt);
|
||||
|
||||
for (auto& sale : sales) {
|
||||
std::map<std::string, Article*> artMap;
|
||||
for (const auto& seller : sellers) {
|
||||
for (const auto article : seller->getArticles(false)) {
|
||||
artMap.insert(std::make_pair(article->getUuidAsString(), article));
|
||||
}
|
||||
}
|
||||
|
||||
retCode = sqlite3_prepare_v2(db_,
|
||||
"SELECT sale_id, article_id"
|
||||
" FROM sales_items"
|
||||
" WHERE sale_id = :sale_uuid",
|
||||
" FROM sales_items",
|
||||
-1, &stmt, nullptr);
|
||||
if (retCode != SQLITE_OK)
|
||||
throw std::runtime_error(sqlite3_errmsg(db_));
|
||||
|
||||
sqlite3_bind_text(stmt, sqlite3_bind_parameter_index(stmt, ":sale_uuid"),
|
||||
sale->getUuidAsString().c_str(), -1, SQLITE_TRANSIENT);
|
||||
|
||||
retCode = sqlite3_step(stmt);
|
||||
|
||||
while (retCode != SQLITE_DONE) {
|
||||
for (auto& seller : sellers) {
|
||||
auto article = seller->getArticleByUuid(
|
||||
reinterpret_cast<const char*>(sqlite3_column_text(stmt, 1)));
|
||||
if (article != nullptr) {
|
||||
sale->addArticle(article);
|
||||
break;
|
||||
}
|
||||
}
|
||||
saleMap[reinterpret_cast<const char*>(sqlite3_column_text(stmt, 0))]->addArticle(
|
||||
artMap[reinterpret_cast<const char*>(sqlite3_column_text(stmt, 1))]);
|
||||
|
||||
retCode = sqlite3_step(stmt);
|
||||
}
|
||||
|
||||
sqlite3_finalize(stmt);
|
||||
}
|
||||
//}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue