mirror of
https://github.com/EQEmu/Server.git
synced 2026-04-27 16:32:27 +00:00
Wrap SaveBuffs delete+replace in a transaction to prevent buff wipe on insert failure
Co-authored-by: Valorith <76063792+Valorith@users.noreply.github.com>
This commit is contained in:
parent
0b86ffd2de
commit
e359852ccf
@ -2877,14 +2877,6 @@ void ZoneDatabase::UpdateAltCurrencyValue(uint32 char_id, uint32 currency_id, ui
|
|||||||
|
|
||||||
void ZoneDatabase::SaveBuffs(Client *client)
|
void ZoneDatabase::SaveBuffs(Client *client)
|
||||||
{
|
{
|
||||||
CharacterBuffsRepository::DeleteWhere(
|
|
||||||
database,
|
|
||||||
fmt::format(
|
|
||||||
"`character_id` = {}",
|
|
||||||
client->CharacterID()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
auto buffs = client->GetBuffs();
|
auto buffs = client->GetBuffs();
|
||||||
const int max_buff_slots = client->GetMaxBuffSlots();
|
const int max_buff_slots = client->GetMaxBuffSlots();
|
||||||
|
|
||||||
@ -2933,9 +2925,20 @@ void ZoneDatabase::SaveBuffs(Client *client)
|
|||||||
v.emplace_back(e);
|
v.emplace_back(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
database.TransactionBegin();
|
||||||
|
|
||||||
|
CharacterBuffsRepository::DeleteWhere(
|
||||||
|
database,
|
||||||
|
fmt::format(
|
||||||
|
"`character_id` = {}",
|
||||||
|
client->CharacterID()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
if (!v.empty()) {
|
if (!v.empty()) {
|
||||||
const auto saved_count = CharacterBuffsRepository::ReplaceMany(database, v);
|
const auto saved_count = CharacterBuffsRepository::ReplaceMany(database, v);
|
||||||
if (saved_count != static_cast<int>(v.size())) {
|
if (saved_count != static_cast<int>(v.size())) {
|
||||||
|
database.TransactionRollback();
|
||||||
LogError(
|
LogError(
|
||||||
"Failed to save all buffs for character [{}] [{}]. Expected [{}] rows, saved [{}]. Verify the `character_buffs` schema is up to date.",
|
"Failed to save all buffs for character [{}] [{}]. Expected [{}] rows, saved [{}]. Verify the `character_buffs` schema is up to date.",
|
||||||
client->GetCleanName(),
|
client->GetCleanName(),
|
||||||
@ -2943,8 +2946,11 @@ void ZoneDatabase::SaveBuffs(Client *client)
|
|||||||
v.size(),
|
v.size(),
|
||||||
saved_count
|
saved_count
|
||||||
);
|
);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
database.TransactionCommit();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZoneDatabase::LoadBuffs(Client *client)
|
void ZoneDatabase::LoadBuffs(Client *client)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user