mirror of
https://github.com/EQEmu/Server.git
synced 2026-06-23 04:18:41 +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:
+23
-8
@@ -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 at least [{}] rows saved, got [{}]. Verify the `character_buffs` schema is up to date.",
|
"Failed to save all buffs for character [{}] [{}]. Expected at least [{}] rows saved, got [{}]. Verify the `character_buffs` schema is up to date.",
|
||||||
client->GetCleanName(),
|
client->GetCleanName(),
|
||||||
@@ -2943,8 +2946,20 @@ void ZoneDatabase::SaveBuffs(Client *client)
|
|||||||
v.size(),
|
v.size(),
|
||||||
saved_count
|
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)
|
void ZoneDatabase::LoadBuffs(Client *client)
|
||||||
|
|||||||
Reference in New Issue
Block a user