From d6d5d992cb685ff27f2a51d858179ee1dca45668 Mon Sep 17 00:00:00 2001 From: nytmyr <53322305+nytmyr@users.noreply.github.com> Date: Mon, 21 Oct 2024 23:57:42 -0500 Subject: [PATCH] [Bots] Fix pet buffs from saving duplicates every save (#4520) * [Bots] Fix pet buffs from saving duplicates every save Previously we were not checking the pet index properly when clearing buffs in the database before saving which resulted in no prior data being deleted. This corrects the logic for the save and also will clean up any buffs for pets that don't exist in the table. * Changes * Update world_boot.cpp --------- Co-authored-by: Akkadius --- world/world_boot.cpp | 7 +++++++ zone/bot_database.cpp | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/world/world_boot.cpp b/world/world_boot.cpp index 859eff534a..831babdb7d 100644 --- a/world/world_boot.cpp +++ b/world/world_boot.cpp @@ -294,6 +294,13 @@ bool WorldBoot::DatabaseLoadRoutines(int argc, char **argv) database.ClearBuyerDetails(); LogInfo("Clearing buyer table details"); + if (RuleB(Bots, Enabled)) { + LogInfo("Clearing [bot_pet_buffs] table of stale entries"); + database.QueryDatabase( + "DELETE FROM bot_pet_buffs WHERE NOT EXISTS (SELECT * FROM bot_pets WHERE bot_pets.pets_index = bot_pet_buffs.pets_index)" + ); + } + if (!content_db.LoadItems(hotfix_name)) { LogError("Error: Could not load item data. But ignoring"); } diff --git a/zone/bot_database.cpp b/zone/bot_database.cpp index dcc5ff89b5..a24cd0c308 100644 --- a/zone/bot_database.cpp +++ b/zone/bot_database.cpp @@ -1451,7 +1451,7 @@ bool BotDatabase::DeletePetBuffs(const uint32 bot_id) return true; } - BotPetBuffsRepository::DeleteOne(database, saved_pet_index); + BotPetBuffsRepository::DeleteWhere(database, fmt::format("pets_index = {}", saved_pet_index)); return true; }