Bulk load goallists

This commit is contained in:
Akkadius 2020-04-11 02:19:58 -05:00
parent 423bb7f0b3
commit 5c7eb0707f
2 changed files with 38 additions and 32 deletions

View File

@ -20,7 +20,7 @@
*/ */
/** /**
* This repository was automatically generated on Apr 5, 2020 and is NOT * This repository was automatically generated on Apr11, 2020 and is NOT
* to be modified directly. Any repository modifications are meant to be made to * to be modified directly. Any repository modifications are meant to be made to
* the repository extending the base. Any modifications to base repositories are to * the repository extending the base. Any modifications to base repositories are to
* be made by the generator only * be made by the generator only
@ -41,7 +41,7 @@ public:
static std::string PrimaryKey() static std::string PrimaryKey()
{ {
return std::string("entry"); return std::string("listid");
} }
static std::vector<std::string> Columns() static std::vector<std::string> Columns()
@ -111,7 +111,7 @@ public:
) )
{ {
for (auto &goallists : goallistss) { for (auto &goallists : goallistss) {
if (goallists.entry == goallists_id) { if (goallists.listid == goallists_id) {
return goallists; return goallists;
} }
} }
@ -168,7 +168,8 @@ public:
auto columns = Columns(); auto columns = Columns();
update_values.push_back(columns[0] + " = " + std::to_string(goallists_entry.listid));
update_values.push_back(columns[1] + " = " + std::to_string(goallists_entry.entry));
auto results = content_db.QueryDatabase( auto results = content_db.QueryDatabase(
fmt::format( fmt::format(
@ -176,7 +177,7 @@ public:
TableName(), TableName(),
implode(", ", update_values), implode(", ", update_values),
PrimaryKey(), PrimaryKey(),
goallists_entry.entry goallists_entry.listid
) )
); );
@ -189,7 +190,8 @@ public:
{ {
std::vector<std::string> insert_values; std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(goallists_entry.listid));
insert_values.push_back(std::to_string(goallists_entry.entry));
auto results = content_db.QueryDatabase( auto results = content_db.QueryDatabase(
fmt::format( fmt::format(
@ -200,7 +202,7 @@ public:
); );
if (results.Success()) { if (results.Success()) {
goallists_entry.id = results.LastInsertedID(); goallists_entry.listid = results.LastInsertedID();
return goallists_entry; return goallists_entry;
} }
@ -218,7 +220,8 @@ public:
for (auto &goallists_entry: goallists_entries) { for (auto &goallists_entry: goallists_entries) {
std::vector<std::string> insert_values; std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(goallists_entry.listid));
insert_values.push_back(std::to_string(goallists_entry.entry));
insert_chunks.push_back("(" + implode(",", insert_values) + ")"); insert_chunks.push_back("(" + implode(",", insert_values) + ")");
} }

View File

@ -30,7 +30,8 @@ Copyright (C) 2001-2008 EQEMu Development Team (http://eqemulator.net)
#include "../common/rulesys.h" #include "../common/rulesys.h"
#include "../common/string_util.h" #include "../common/string_util.h"
#include "../common/say_link.h" #include "../common/say_link.h"
#include "zonedb.h"
#include "../common/repositories/goallists_repository.h"
#include "client.h" #include "client.h"
#include "entity.h" #include "entity.h"
#include "mob.h" #include "mob.h"
@ -972,7 +973,7 @@ int TaskManager::GetTaskMinLevel(int TaskID)
{ {
return Tasks[TaskID]->MinLevel; return Tasks[TaskID]->MinLevel;
} }
return -1; return -1;
} }
@ -3370,42 +3371,44 @@ bool TaskGoalListManager::LoadLists()
TaskGoalLists.reserve(NumberOfLists); TaskGoalLists.reserve(NumberOfLists);
int listIndex = 0; int list_index = 0;
for (auto row = results.begin(); row != results.end(); ++row) { for (auto row = results.begin(); row != results.end(); ++row) {
int listID = atoi(row[0]); int listID = atoi(row[0]);
int listSize = atoi(row[1]); int listSize = atoi(row[1]);
TaskGoalLists.push_back({listID, 0, 0}); TaskGoalLists.push_back({listID, 0, 0});
TaskGoalLists[listIndex].GoalItemEntries.reserve(listSize); TaskGoalLists[list_index].GoalItemEntries.reserve(listSize);
listIndex++; list_index++;
} }
for (int listIndex = 0; listIndex < NumberOfLists; listIndex++) { auto goal_lists = GoallistsRepository::GetWhere("TRUE ORDER BY listid, entry ASC");
int listID = TaskGoalLists[listIndex].ListID; for (list_index = 0; list_index < NumberOfLists; list_index++) {
auto size = TaskGoalLists[listIndex].GoalItemEntries.capacity(); // this was only done for manual memory management, shouldn't need to do this
query = StringFormat("SELECT `entry` from `goallists` "
"WHERE `listid` = %i "
"ORDER BY `entry` ASC LIMIT %i",
listID, size);
results = content_db.QueryDatabase(query);
if (!results.Success()) {
continue;
}
for (auto row = results.begin(); row != results.end(); ++row) { int list_id = TaskGoalLists[list_index].ListID;
int entry = atoi(row[0]); for (auto &entry: goal_lists) {
if (entry.listid == list_id) {
if (entry.entry < TaskGoalLists[list_index].Min) {
TaskGoalLists[list_index].Min = entry.entry;
}
if (entry < TaskGoalLists[listIndex].Min) if (entry.entry > TaskGoalLists[list_index].Max) {
TaskGoalLists[listIndex].Min = entry; TaskGoalLists[list_index].Max = entry.entry;
}
if (entry > TaskGoalLists[listIndex].Max) TaskGoalLists[list_index].GoalItemEntries.push_back(entry.entry);
TaskGoalLists[listIndex].Max = entry;
TaskGoalLists[listIndex].GoalItemEntries.push_back(entry); LogTasksDetail(
"Goal list index [{}] loading list [{}] entry [{}]",
list_index,
list_id,
entry.entry
);
}
} }
} }