Skip to content

Commit

Permalink
[Bots] Fix pet buffs from saving duplicates every save (#4520)
Browse files Browse the repository at this point in the history
* [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 <[email protected]>
  • Loading branch information
nytmyr and Akkadius authored Oct 22, 2024
1 parent d524cb6 commit d6d5d99
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 7 additions & 0 deletions world/world_boot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
2 changes: 1 addition & 1 deletion zone/bot_database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit d6d5d99

Please sign in to comment.