[Bots] Fix Slow Query in QueryNameAvailablity (#2781)

This commit is contained in:
Aeadoin 2023-01-22 18:26:57 -05:00 committed by GitHub
parent 7e35d5aa79
commit 293f79268d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 3 deletions

View File

@ -35,7 +35,7 @@
*/
#define CURRENT_BINARY_DATABASE_VERSION 9217
#define CURRENT_BINARY_BOTS_DATABASE_VERSION 9036
#define CURRENT_BINARY_BOTS_DATABASE_VERSION 9037
#define COMPILE_DATE __DATE__
#define COMPILE_TIME __TIME__

View File

@ -35,6 +35,7 @@
9034|2022_12_02_bot_spell_settings.sql|SHOW COLUMNS FROM `bot_data` LIKE 'enforce_spell_settings'|empty|
9035|2022_12_04_bot_archery.sql|SHOW COLUMNS FROM `bot_data` LIKE 'archery_setting'|empty|
9036|2023_01_19_drop_bot_views.sql|SHOW TABLES LIKE 'vw_groups'|not_empty|
9037|2023_01_22_add_name_index.sql||show index from bot_data WHERE key_name = 'name`|empty|
# Upgrade conditions:
# This won't be needed after this system is implemented, but it is used database that are not

View File

@ -0,0 +1 @@
create index `name` on bot_data(`name`);

View File

@ -173,13 +173,23 @@ bool BotDatabase::QueryNameAvailablity(const std::string& bot_name, bool& availa
query = fmt::format(
"SELECT b.bot_id FROM bot_data b "
"INNER JOIN character_data c ON b.`name` = c.`name` "
"WHERE b.`name` LIKE '{0}' OR c.`name` LIKE '{0}' "
"WHERE b.`name` LIKE '{}' "
"LIMIT 1",
bot_name
);
auto results = database.QueryDatabase(query);
if (!results.RowCount()) {
query = fmt::format(
"SELECT c.id FROM character_data c "
"WHERE c.`name` LIKE '{}' "
"LIMIT 1",
bot_name
);
results = database.QueryDatabase(query);
}
if (!results.Success()) {
return false;
}