Skip to content

Commit

Permalink
Chat: Add some performance improvements to .go creature name
Browse files Browse the repository at this point in the history
  • Loading branch information
killerwife committed Jan 14, 2024
1 parent 27999d8 commit da2ab74
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/game/Chat/Level2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -582,11 +582,11 @@ bool ChatHandler::HandleGoCreatureCommand(char* args)
{
std::string name = pParam1;
WorldDatabase.escape_string(name);
auto queryResult = WorldDatabase.PQuery("SELECT creature.guid, creature_spawn_entry.guid "
"FROM creature, creature_template, creature_spawn_entry "
"WHERE (creature.id = creature_template.entry "
"OR (creature_spawn_entry.entry = creature_template.entry AND creature.guid = creature_spawn_entry.guid)) "
"AND creature_template.name LIKE '%%%s%%' LIMIT 1;", name.c_str());
auto queryResult = WorldDatabase.PQuery("SELECT COALESCE(creature.guid, creature_spawn_entry.guid) AS guid "
"FROM creature_template "
"LEFT JOIN creature ON creature.id = creature_template.entry "
"LEFT JOIN creature_spawn_entry ON creature_spawn_entry.entry = creature_template.entry "
"WHERE creature_template.name LIKE '%%%s%%' LIMIT 1;", name.c_str());
if (!queryResult)
{
SendSysMessage(LANG_COMMAND_GOCREATNOTFOUND);
Expand All @@ -613,6 +613,7 @@ bool ChatHandler::HandleGoCreatureCommand(char* args)
break;

data = &dataPair->second;
dbGuid = dataPair->first;
}
break;
}
Expand Down Expand Up @@ -666,12 +667,12 @@ bool ChatHandler::HandleGoCreatureCommand(char* args)
Creature* creature = nullptr;
if (dbGuid)
{
// check static creature store
creature = map->GetCreature(ObjectGuid(HIGHGUID_UNIT, dbGuid));
// check creature with dynamic guid
creature = map->GetCreature(dbGuid);
if (!creature)
{
// check creature with dynamic guid
creature = map->GetCreature(dbGuid);
// check static creature store
creature = map->GetCreature(ObjectGuid(HIGHGUID_UNIT, dbGuid));
}
}
/*else
Expand Down

0 comments on commit da2ab74

Please sign in to comment.