mirror of
https://github.com/EQEmu/Server.git
synced 2026-03-10 10:12:24 +00:00
Cut down on task saves
This commit is contained in:
parent
2c1cb55f14
commit
01fd2611e6
@ -290,6 +290,12 @@ bool TaskManager::SaveClientState(Client *client, ClientTaskState *cts)
|
|||||||
|
|
||||||
LogTasks("character_id [{}]", character_id);
|
LogTasks("character_id [{}]", character_id);
|
||||||
|
|
||||||
|
auto ct = CharacterTasksRepository::NewEntity();
|
||||||
|
std::vector<CharacterTasksRepository::CharacterTasks> ct_entries;
|
||||||
|
|
||||||
|
auto cta = CharacterActivitiesRepository::NewEntity();
|
||||||
|
std::vector<CharacterActivitiesRepository::CharacterActivities> cta_entries;
|
||||||
|
|
||||||
if (cts->m_active_task_count > 0 ||
|
if (cts->m_active_task_count > 0 ||
|
||||||
cts->m_active_task.task_id != TASKSLOTEMPTY ||
|
cts->m_active_task.task_id != TASKSLOTEMPTY ||
|
||||||
cts->m_active_shared_task.task_id != TASKSLOTEMPTY) {
|
cts->m_active_shared_task.task_id != TASKSLOTEMPTY) {
|
||||||
@ -303,7 +309,6 @@ bool TaskManager::SaveClientState(Client *client, ClientTaskState *cts)
|
|||||||
|
|
||||||
int slot = active_task.slot;
|
int slot = active_task.slot;
|
||||||
if (active_task.updated) {
|
if (active_task.updated) {
|
||||||
|
|
||||||
LogTasks(
|
LogTasks(
|
||||||
"character_id [{}] updating task_index [{}] task_id [{}]",
|
"character_id [{}] updating task_index [{}] task_id [{}]",
|
||||||
character_id,
|
character_id,
|
||||||
@ -311,32 +316,15 @@ bool TaskManager::SaveClientState(Client *client, ClientTaskState *cts)
|
|||||||
task_id
|
task_id
|
||||||
);
|
);
|
||||||
|
|
||||||
std::string query = StringFormat(
|
ct.charid = character_id;
|
||||||
"REPLACE INTO character_tasks (charid, taskid, slot, type, acceptedtime, was_rewarded) "
|
ct.taskid = task_id;
|
||||||
"VALUES (%i, %i, %i, %i, %i, %d)",
|
ct.slot = slot;
|
||||||
character_id,
|
ct.type = static_cast<int>(task_data->type);
|
||||||
task_id,
|
ct.acceptedtime = active_task.accepted_time;
|
||||||
slot,
|
ct.was_rewarded = active_task.was_rewarded;
|
||||||
static_cast<int>(task_data->type),
|
ct_entries.emplace_back(ct);
|
||||||
active_task.accepted_time,
|
|
||||||
active_task.was_rewarded
|
|
||||||
);
|
|
||||||
|
|
||||||
auto results = database.QueryDatabase(query);
|
|
||||||
if (!results.Success()) {
|
|
||||||
LogError(ERR_MYSQLERROR, results.ErrorMessage().c_str());
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
active_task.updated = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string query =
|
|
||||||
"REPLACE INTO character_activities (charid, taskid, activityid, donecount, completed) "
|
|
||||||
"VALUES ";
|
|
||||||
|
|
||||||
int updated_activity_count = 0;
|
|
||||||
|
|
||||||
for (int activity_index = 0; activity_index < task_data->activity_count; ++activity_index) {
|
for (int activity_index = 0; activity_index < task_data->activity_count; ++activity_index) {
|
||||||
if (!active_task.activity[activity_index].updated) {
|
if (!active_task.activity[activity_index].updated) {
|
||||||
continue;
|
continue;
|
||||||
@ -350,54 +338,31 @@ bool TaskManager::SaveClientState(Client *client, ClientTaskState *cts)
|
|||||||
activity_index
|
activity_index
|
||||||
);
|
);
|
||||||
|
|
||||||
if (updated_activity_count == 0) {
|
cta.charid = character_id;
|
||||||
query +=
|
cta.taskid = task_id;
|
||||||
StringFormat(
|
cta.activityid = activity_index;
|
||||||
"(%i, %i, %i, %i, %i)", character_id, task_id, activity_index,
|
cta.donecount = active_task.activity[activity_index].done_count;
|
||||||
active_task.activity[activity_index].done_count,
|
cta.completed = active_task.activity[activity_index].activity_state == ActivityCompleted ? 1 : 0;
|
||||||
active_task.activity[activity_index].activity_state ==
|
cta_entries.emplace_back(cta);
|
||||||
ActivityCompleted
|
|
||||||
);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
query +=
|
|
||||||
StringFormat(
|
|
||||||
", (%i, %i, %i, %i, %i)", character_id, task_id, activity_index,
|
|
||||||
active_task.activity[activity_index].done_count,
|
|
||||||
active_task.activity[activity_index].activity_state ==
|
|
||||||
ActivityCompleted
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
updated_activity_count++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (updated_activity_count == 0) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto results = database.QueryDatabase(query);
|
|
||||||
|
|
||||||
if (!results.Success()) {
|
|
||||||
LogError(ERR_MYSQLERROR, results.ErrorMessage().c_str());
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
active_task.updated = false;
|
|
||||||
for (int activity_index = 0; activity_index < task_data->activity_count; ++activity_index) {
|
|
||||||
active_task.activity[activity_index].updated = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!ct_entries.empty()) {
|
||||||
|
CharacterTasksRepository::ReplaceMany(content_db, ct_entries);
|
||||||
|
}
|
||||||
|
if (!cta_entries.empty()) {
|
||||||
|
CharacterActivitiesRepository::ReplaceMany(content_db, cta_entries);
|
||||||
|
}
|
||||||
|
|
||||||
if (!RuleB(TaskSystem, RecordCompletedTasks) || (cts->m_completed_tasks.size() <=
|
if (!RuleB(TaskSystem, RecordCompletedTasks) || (cts->m_completed_tasks.size() <=
|
||||||
(unsigned int) cts->m_last_completed_task_loaded)) {
|
(unsigned int) cts->m_last_completed_task_loaded)) {
|
||||||
cts->m_last_completed_task_loaded = cts->m_completed_tasks.size();
|
cts->m_last_completed_task_loaded = cts->m_completed_tasks.size();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *completed_task_query = "REPLACE INTO completed_tasks (charid, completedtime, taskid, activityid) "
|
auto completed_task = CompletedTasksRepository::NewEntity();
|
||||||
"VALUES (%i, %i, %i, %i)";
|
std::vector<CompletedTasksRepository::CompletedTasks> completed_task_entries;
|
||||||
|
|
||||||
for (
|
for (
|
||||||
unsigned int task_index = cts->m_last_completed_task_loaded;
|
unsigned int task_index = cts->m_last_completed_task_loaded;
|
||||||
@ -423,19 +388,11 @@ bool TaskManager::SaveClientState(Client *client, ClientTaskState *cts)
|
|||||||
// This indicates this task was completed at the given time. We infer that all
|
// This indicates this task was completed at the given time. We infer that all
|
||||||
// none optional activities were completed.
|
// none optional activities were completed.
|
||||||
//
|
//
|
||||||
std::string query = StringFormat(
|
completed_task.charid = character_id;
|
||||||
completed_task_query,
|
completed_task.completedtime = t.completed_time;
|
||||||
character_id,
|
completed_task.taskid = task_id;
|
||||||
t.completed_time,
|
completed_task.activityid = -1;
|
||||||
task_id,
|
completed_task_entries.emplace_back(completed_task);
|
||||||
-1
|
|
||||||
);
|
|
||||||
|
|
||||||
auto results = database.QueryDatabase(query);
|
|
||||||
if (!results.Success()) {
|
|
||||||
LogError(ERR_MYSQLERROR, results.ErrorMessage().c_str());
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the Rule to record non-optional task completion is not enabled, don't save it
|
// If the Rule to record non-optional task completion is not enabled, don't save it
|
||||||
if (!RuleB(TaskSystem, RecordCompletedOptionalActivities)) {
|
if (!RuleB(TaskSystem, RecordCompletedOptionalActivities)) {
|
||||||
@ -449,20 +406,18 @@ bool TaskManager::SaveClientState(Client *client, ClientTaskState *cts)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
query = StringFormat(
|
completed_task.charid = character_id;
|
||||||
completed_task_query,
|
completed_task.completedtime = t.completed_time;
|
||||||
character_id,
|
completed_task.taskid = task_id;
|
||||||
t.completed_time,
|
completed_task.activityid = activity_id;
|
||||||
task_id, activity_id
|
completed_task_entries.emplace_back(completed_task);
|
||||||
);
|
|
||||||
|
|
||||||
results = database.QueryDatabase(query);
|
|
||||||
if (!results.Success()) {
|
|
||||||
LogError(ERR_MYSQLERROR, results.ErrorMessage().c_str());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!completed_task_entries.empty()) {
|
||||||
|
CompletedTasksRepository::ReplaceMany(content_db, completed_task_entries);
|
||||||
|
}
|
||||||
|
|
||||||
cts->m_last_completed_task_loaded = cts->m_completed_tasks.size();
|
cts->m_last_completed_task_loaded = cts->m_completed_tasks.size();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user