mirror of
https://github.com/EQEmu/Server.git
synced 2026-05-03 22:32:26 +00:00
Merge pull request #57 from Valorith/copilot/sub-pr-55-again
Wrap SaveBuffs delete+replace in a transaction to prevent buff wipe on insert failure
This commit is contained in:
commit
099da0e031
@ -2877,14 +2877,6 @@ void ZoneDatabase::UpdateAltCurrencyValue(uint32 char_id, uint32 currency_id, ui
|
||||
|
||||
void ZoneDatabase::SaveBuffs(Client *client)
|
||||
{
|
||||
CharacterBuffsRepository::DeleteWhere(
|
||||
database,
|
||||
fmt::format(
|
||||
"`character_id` = {}",
|
||||
client->CharacterID()
|
||||
)
|
||||
);
|
||||
|
||||
auto buffs = client->GetBuffs();
|
||||
const int max_buff_slots = client->GetMaxBuffSlots();
|
||||
|
||||
@ -2933,9 +2925,20 @@ void ZoneDatabase::SaveBuffs(Client *client)
|
||||
v.emplace_back(e);
|
||||
}
|
||||
|
||||
database.TransactionBegin();
|
||||
|
||||
CharacterBuffsRepository::DeleteWhere(
|
||||
database,
|
||||
fmt::format(
|
||||
"`character_id` = {}",
|
||||
client->CharacterID()
|
||||
)
|
||||
);
|
||||
|
||||
if (!v.empty()) {
|
||||
const auto saved_count = CharacterBuffsRepository::ReplaceMany(database, v);
|
||||
if (saved_count < static_cast<int>(v.size())) {
|
||||
database.TransactionRollback();
|
||||
LogError(
|
||||
"Failed to save all buffs for character [{}] [{}]. Expected at least [{}] rows saved, got [{}]. Verify the `character_buffs` schema is up to date.",
|
||||
client->GetCleanName(),
|
||||
@ -2943,8 +2946,20 @@ void ZoneDatabase::SaveBuffs(Client *client)
|
||||
v.size(),
|
||||
saved_count
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const auto commit_result = database.TransactionCommit();
|
||||
if (!commit_result.Success()) {
|
||||
database.TransactionRollback();
|
||||
LogError(
|
||||
"Failed to commit buff save transaction for character [{}] [{}]: {}",
|
||||
client->GetCleanName(),
|
||||
client->CharacterID(),
|
||||
commit_result.ErrorMessage()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void ZoneDatabase::LoadBuffs(Client *client)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user