mirror of
https://github.com/EQEmu/Server.git
synced 2025-12-12 09:31:30 +00:00
[Performance] Character buffs now save in bulk (#3336)
* [Performance] Character buffs now save in bulk * Only insert if we have buffs to insert * Swap for .empty()
This commit is contained in:
parent
50c63b95db
commit
c44c0d4efa
@ -17,6 +17,7 @@
|
|||||||
#include "../common/repositories/character_pet_buffs_repository.h"
|
#include "../common/repositories/character_pet_buffs_repository.h"
|
||||||
#include "../common/repositories/character_pet_inventory_repository.h"
|
#include "../common/repositories/character_pet_inventory_repository.h"
|
||||||
#include "../common/repositories/character_pet_info_repository.h"
|
#include "../common/repositories/character_pet_info_repository.h"
|
||||||
|
#include "../common/repositories/character_buffs_repository.h"
|
||||||
|
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@ -3058,29 +3059,62 @@ void ZoneDatabase::UpdateAltCurrencyValue(uint32 char_id, uint32 currency_id, ui
|
|||||||
|
|
||||||
void ZoneDatabase::SaveBuffs(Client *client) {
|
void ZoneDatabase::SaveBuffs(Client *client) {
|
||||||
|
|
||||||
std::string query = StringFormat("DELETE FROM `character_buffs` WHERE `character_id` = '%u'", client->CharacterID());
|
// delete the character buffs
|
||||||
database.QueryDatabase(query);
|
CharacterBuffsRepository::DeleteWhere(database, fmt::format("character_id = {}", client->CharacterID()));
|
||||||
|
|
||||||
|
// get the character buffs
|
||||||
uint32 buff_count = client->GetMaxBuffSlots();
|
uint32 buff_count = client->GetMaxBuffSlots();
|
||||||
Buffs_Struct *buffs = client->GetBuffs();
|
Buffs_Struct *buffs = client->GetBuffs();
|
||||||
|
|
||||||
|
// character buffs struct
|
||||||
|
auto b = CharacterBuffsRepository::NewEntity();
|
||||||
|
|
||||||
|
// vector of character buffs
|
||||||
|
std::vector<CharacterBuffsRepository::CharacterBuffs> character_buffs = {};
|
||||||
|
|
||||||
|
// count the number of buffs that are valid
|
||||||
|
int character_buff_count = 0;
|
||||||
|
for (int index = 0; index < buff_count; index++) {
|
||||||
|
if (!IsValidSpell(buffs[index].spellid)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
character_buff_count++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// allocate memory for the character buffs
|
||||||
|
character_buffs.reserve(character_buff_count);
|
||||||
|
|
||||||
for (int index = 0; index < buff_count; index++) {
|
for (int index = 0; index < buff_count; index++) {
|
||||||
if (!IsValidSpell(buffs[index].spellid)) {
|
if (!IsValidSpell(buffs[index].spellid)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
query = StringFormat("INSERT INTO `character_buffs` (character_id, slot_id, spell_id, "
|
// fill in the buff struct
|
||||||
"caster_level, caster_name, ticsremaining, counters, numhits, melee_rune, "
|
b.character_id = client->CharacterID();
|
||||||
"magic_rune, persistent, dot_rune, caston_x, caston_y, caston_z, ExtraDIChance, "
|
b.slot_id = index;
|
||||||
"instrument_mod) "
|
b.spell_id = buffs[index].spellid;
|
||||||
"VALUES('%u', '%u', '%u', '%u', '%s', '%d', '%u', '%u', '%u', '%u', '%u', '%u', "
|
b.caster_level = buffs[index].casterlevel;
|
||||||
"'%i', '%i', '%i', '%i', '%i')", client->CharacterID(), index, buffs[index].spellid,
|
b.caster_name = buffs[index].caster_name;
|
||||||
buffs[index].casterlevel, buffs[index].caster_name, buffs[index].ticsremaining,
|
b.ticsremaining = buffs[index].ticsremaining;
|
||||||
buffs[index].counters, buffs[index].hit_number, buffs[index].melee_rune,
|
b.counters = buffs[index].counters;
|
||||||
buffs[index].magic_rune, buffs[index].persistant_buff, buffs[index].dot_rune,
|
b.numhits = buffs[index].hit_number;
|
||||||
buffs[index].caston_x, buffs[index].caston_y, buffs[index].caston_z,
|
b.melee_rune = buffs[index].melee_rune;
|
||||||
buffs[index].ExtraDIChance, buffs[index].instrument_mod);
|
b.magic_rune = buffs[index].magic_rune;
|
||||||
QueryDatabase(query);
|
b.persistent = buffs[index].persistant_buff;
|
||||||
|
b.dot_rune = buffs[index].dot_rune;
|
||||||
|
b.caston_x = buffs[index].caston_x;
|
||||||
|
b.caston_y = buffs[index].caston_y;
|
||||||
|
b.caston_z = buffs[index].caston_z;
|
||||||
|
b.ExtraDIChance = buffs[index].ExtraDIChance;
|
||||||
|
b.instrument_mod = buffs[index].instrument_mod;
|
||||||
|
|
||||||
|
// add the buff to the vector
|
||||||
|
character_buffs.emplace_back(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
// insert the buffs into the database
|
||||||
|
if (!character_buffs.empty()) {
|
||||||
|
CharacterBuffsRepository::InsertMany(database, character_buffs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user