From 11584a68d694b83fc890f7d3186d4f8c324a1342 Mon Sep 17 00:00:00 2001 From: Sarjuuk Date: Tue, 11 Aug 2015 14:44:55 +0200 Subject: [PATCH] Profiler preparations * Setup - accessing realm info by way of Util function - added table ?_talents * Lists - added support for querying multiple databases with the same structure at once (read: realms) - added support for exact string matches and forcing collate of fields to ci * JS - renamed occurences of 'subregion' to 'battlegroup' to be in line with other scripts (the usage is the same) --- includes/types/basetype.class.php | 48 ++++++++++++++++++++------ includes/utilities.php | 9 +++++ setup/db_structure.sql | 21 +++++++++++ setup/tools/clisetup/firstrun.func.php | 1 + setup/tools/filegen/realmMenu.func.php | 34 ++++++++---------- setup/tools/filegen/realms.func.php | 9 ++--- setup/tools/sqlGen.class.php | 1 + setup/tools/sqlgen/talents.func.php | 26 ++++++++++++++ setup/updates/1439297934_01.sql | 15 ++++++++ static/js/global.js | 14 ++++---- 10 files changed, 137 insertions(+), 41 deletions(-) create mode 100644 setup/tools/sqlgen/talents.func.php create mode 100644 setup/updates/1439297934_01.sql diff --git a/includes/types/basetype.class.php b/includes/types/basetype.class.php index 91b911e1..fe221e95 100644 --- a/includes/types/basetype.class.php +++ b/includes/types/basetype.class.php @@ -11,8 +11,9 @@ abstract class BaseType protected $templates = []; protected $curTpl = []; // lets iterate! - protected $matches = null; // total matches unaffected by sqlLimit in config + protected $matches = 0; // total matches unaffected by sqlLimit in config + protected $dbNames = ['Aowow']; // multiple DBs in profiler protected $queryBase = ''; protected $queryOpts = []; @@ -68,7 +69,7 @@ abstract class BaseType if ($miscData && !empty($miscData['extraOpts'])) $this->extendQueryOpts($miscData['extraOpts']); - $resolveCondition = function ($c, $supLink) use (&$resolveCondition, &$prefixes) + $resolveCondition = function ($c, $supLink) use (&$resolveCondition, &$prefixes, $miscData) { $subLink = ''; @@ -168,6 +169,9 @@ abstract class BaseType } else if (is_string($c[1])) { + if (!empty($miscData['forceCiCollate'])) + $field .= ' COLLATE utf8_general_ci'; + $op = (isset($c[2]) && $c[2] == '!') ? 'NOT LIKE' : 'LIKE'; $val = DB::Aowow()->escape($c[1]); } @@ -219,6 +223,10 @@ abstract class BaseType if (!in_array($k, $prefixes)) unset($this->queryOpts[$k]); + // prepare usage of guids if using multiple DBs + if (count($this->dbNames) > 1) + $this->queryBase = preg_replace('/\s([^\s]+)\sAS\sARRAY_KEY/i', ' CONCAT("DB_IDX", ":", \1) AS ARRAY_KEY', $this->queryBase); + // insert additional selected fields if ($s = array_column($this->queryOpts, 's')) $this->queryBase = str_replace('ARRAY_KEY', 'ARRAY_KEY '.implode('', $s), $this->queryBase); @@ -248,9 +256,27 @@ abstract class BaseType if ($limit) $this->queryBase .= ' LIMIT '.$limit; - // execure query (finally) - $rows = DB::Aowow()->SelectPage($this->matches, $this->queryBase); - if (!$rows) + // execute query (finally) + $mtch = 0; + // this is purely because of multiple realms per server + foreach ($this->dbNames as $dbIdx => $n) + { + $query = str_replace('DB_IDX', $dbIdx, $this->queryBase); + + if ($rows = DB::{$n}($dbIdx)->SelectPage($mtch, $query)) + { + $this->matches += $mtch; + foreach ($rows as $id => $row) + { + if (isset($this->templates[$id])) + trigger_error('guid for List already in use #'.$id, E_USER_WARNING); + else + $this->templates[$id] = $row; + } + } + } + + if (!$this->templates) return; // assign query results to template @@ -886,23 +912,23 @@ abstract class Filter } } - protected function modularizeString(array $fields, $string = '') + protected function modularizeString(array $fields, $string = '', $exact = false) { if (!$string && !empty($this->fiData['v']['na'])) $string = $this->fiData['v']['na']; - $qry = []; + $qry = []; + $exPH = $exact ? '%s' : '%%%s%%'; foreach ($fields as $n => $f) { - $sub = []; + $sub = []; $parts = array_filter(explode(' ', $string)); - foreach ($parts as $p) { if ($p[0] == '-' && strlen($p) > 3) - $sub[] = [$f, '%'.substr($p, 1).'%', '!']; + $sub[] = [$f, sprintf($exPH, substr($p, 1)), '!']; else if ($p[0] != '-' && strlen($p) > 2) - $sub[] = [$f, '%'.$p.'%']; + $sub[] = [$f, sprintf($exPH, $p)]; } // single cnd? diff --git a/includes/utilities.php b/includes/utilities.php index 0fb55b03..f92f8438 100644 --- a/includes/utilities.php +++ b/includes/utilities.php @@ -1591,6 +1591,15 @@ class Util return false; } + + private static $realms; + public static function getRealms() + { + if (DB::isConnectable(DB_AUTH) && !self::$realms) + self::$realms = DB::Auth()->select('SELECT id AS ARRAY_KEY, name, IF(timezone IN (8, 9, 10, 11, 12), "eu", "us") AS region FROM realmlist WHERE allowedSecurityLevel = 0 AND gamebuild = ?d', WOW_BUILD); + + return self::$realms; + } } ?> diff --git a/setup/db_structure.sql b/setup/db_structure.sql index f81c5a5c..85c99d94 100644 --- a/setup/db_structure.sql +++ b/setup/db_structure.sql @@ -2201,6 +2201,27 @@ CREATE TABLE `aowow_spellvariables` ( ) ENGINE=MyISAM DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Table structure for table `aowow_talents` +-- + +DROP TABLE IF EXISTS `aowow_talents`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `aowow_talents` ( + `id` smallint(5) unsigned NOT NULL, + `class` tinyint(3) unsigned NOT NULL, + `tab` tinyint(3) unsigned NOT NULL, + `row` tinyint(3) unsigned NOT NULL, + `col` tinyint(3) unsigned NOT NULL, + `spell` mediumint(8) unsigned NOT NULL, + `rank` tinyint(3) unsigned NOT NULL, + PRIMARY KEY (`id`, `rank`), + INDEX `spell` (`spell`), + INDEX `class` (`class`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8; +/*!40101 SET character_set_client = @saved_cs_client */; + -- -- Table structure for table `aowow_taxinodes` -- diff --git a/setup/tools/clisetup/firstrun.func.php b/setup/tools/clisetup/firstrun.func.php index 821cbe08..244020ca 100644 --- a/setup/tools/clisetup/firstrun.func.php +++ b/setup/tools/clisetup/firstrun.func.php @@ -44,6 +44,7 @@ function firstrun($resume) ['SqlGen::generate', 'spellrange', null, null, null], ['SqlGen::generate', 'spellvariables', null, null, null], ['SqlGen::generate', 'totemcategory', null, null, null], + ['SqlGen::generate', 'talents', null, null, null], ['SqlGen::generate', 'classes', null, null, null], ['SqlGen::generate', 'factions', null, null, null], ['SqlGen::generate', 'factiontemplate', null, null, null], diff --git a/setup/tools/filegen/realmMenu.func.php b/setup/tools/filegen/realmMenu.func.php index 38d5ee8b..1e40bb43 100644 --- a/setup/tools/filegen/realmMenu.func.php +++ b/setup/tools/filegen/realmMenu.func.php @@ -42,36 +42,32 @@ if (!CLI) $subUS = []; $set = 0x0; $menu = [ - ['us', 'US & Oceanic', null,[[Util::urlize(CFG_BATTLEGROUP), CFG_BATTLEGROUP, null, &$subEU]]], - ['eu', 'Europe', null,[[Util::urlize(CFG_BATTLEGROUP), CFG_BATTLEGROUP, null, &$subUS]]] + ['us', 'US & Oceanic', null,[[Util::urlize(CFG_BATTLEGROUP), CFG_BATTLEGROUP, null, &$subUS]]], + ['eu', 'Europe', null,[[Util::urlize(CFG_BATTLEGROUP), CFG_BATTLEGROUP, null, &$subEU]]] ]; - if (DB::isConnectable(DB_AUTH)) + foreach (Util::getRealms() as $row) { - $rows = DB::Auth()->select('SELECT name, IF(timezone IN (8, 9, 10, 11, 12), "eu", "us") AS region FROM realmlist WHERE allowedSecurityLevel = 0 AND gamebuild = ?d', WOW_BUILD); - - foreach ($rows as $row) + if ($row['region'] == 'eu') { - if ($row['region'] == 'eu') - { - $set |= 0x1; - $subEU[] = [Util::urlize($row['name']), $row['name']]; - } - else if ($row['region'] == 'us') - { - $set |= 0x2; - $subUS[] = [Util::urlize($row['name']), $row['name']]; - } + $set |= 0x1; + $subEU[] = [Util::urlize($row['name']), $row['name']]; + } + else if ($row['region'] == 'us') + { + $set |= 0x2; + $subUS[] = [Util::urlize($row['name']), $row['name']]; } } - else + + if (!$set) CLISetup::log(' - realmMenu: Auth-DB not set up .. menu will be empty', CLISetup::LOG_WARN); if (!($set & 0x1)) - array_shift($menu); + array_pop($menu); if (!($set & 0x2)) - array_pop($menu); + array_shift($menu); return Util::toJSON($menu); } diff --git a/setup/tools/filegen/realms.func.php b/setup/tools/filegen/realms.func.php index 8d189758..eb20ea8a 100644 --- a/setup/tools/filegen/realms.func.php +++ b/setup/tools/filegen/realms.func.php @@ -28,11 +28,12 @@ if (!CLI) function realms() { - $realms = []; - if (DB::isConnectable(DB_AUTH)) - $realms = DB::Auth()->select('SELECT id AS ARRAY_KEY, name, ? AS battlegroup, IF(timezone IN (8, 9, 10, 11, 12), "eu", "us") AS region FROM realmlist WHERE allowedSecurityLevel = 0 AND gamebuild = ?d', CFG_BATTLEGROUP, WOW_BUILD); - else + $realms = Util::getRealms(); + if (!$realms) CLISetup::log(' - realms: Auth-DB not set up .. static data g_realms will be empty', CLISetup::LOG_WARN); + else + foreach ($realms as &$r) + $r['battlegroup'] = CFG_BATTLEGROUP; $toFile = "var g_realms = ".Util::toJSON($realms).";"; $file = 'datasets/realms'; diff --git a/setup/tools/sqlGen.class.php b/setup/tools/sqlGen.class.php index 49e2a5d7..38cdfd11 100644 --- a/setup/tools/sqlGen.class.php +++ b/setup/tools/sqlGen.class.php @@ -41,6 +41,7 @@ class SqlGen 'spellrange' => ['spellrange', false, null, null], 'spellvariables' => ['spelldescriptionvariables', false, null, null], 'totemcategory' => ['totemcategory', false, null, null], + 'talents' => [null, null, null, null], 'classes' => [null, null, null, null], 'factions' => [null, null, null, null], 'factiontemplate' => [null, null, null, null], diff --git a/setup/tools/sqlgen/talents.func.php b/setup/tools/sqlgen/talents.func.php new file mode 100644 index 00000000..742fd569 --- /dev/null +++ b/setup/tools/sqlgen/talents.func.php @@ -0,0 +1,26 @@ + hunter pets + for ($i = 1; $i < 6; $i++) + DB::Aowow()->query( + 'REPLACE INTO ?_talents SELECT t.Id, IF(tt.classMask <> 0, LOG(2, tt.classMask) + 1, 0), IF(tt.creaturefamilyMask <> 0, LOG(2, tt.creaturefamilyMask), tt.tabNumber), t.row, t.column, t.rank?d, ?d FROM dbc_talenttab tt JOIN dbc_talent t ON tt.Id = t.tabId WHERE t.rank?d <> 0', + $i, $i, $i + ); + + return true; +} + +?> \ No newline at end of file diff --git a/setup/updates/1439297934_01.sql b/setup/updates/1439297934_01.sql new file mode 100644 index 00000000..51f5e0a3 --- /dev/null +++ b/setup/updates/1439297934_01.sql @@ -0,0 +1,15 @@ +DROP TABLE IF EXISTS `aowow_talents`; +CREATE TABLE `aowow_talents` ( + `id` smallint(5) unsigned NOT NULL, + `class` tinyint(3) unsigned NOT NULL, + `tab` tinyint(3) unsigned NOT NULL, + `row` tinyint(3) unsigned NOT NULL, + `col` tinyint(3) unsigned NOT NULL, + `spell` mediumint(8) unsigned NOT NULL, + `rank` tinyint(3) unsigned NOT NULL, + PRIMARY KEY (`id`, `rank`), + INDEX `spell` (`spell`), + INDEX `class` (`class`) +) ENGINE=MyISAM; + +UPDATE `aowow_dbversion` SET `sql` = CONCAT(`sql`, ' talents'); diff --git a/static/js/global.js b/static/js/global.js index 417c7504..2a1e88b0 100644 --- a/static/js/global.js +++ b/static/js/global.js @@ -15059,13 +15059,13 @@ Listview.templates = { $WH.ae(a, $WH.ct(profile.region.toUpperCase())); $WH.ae(s, a); - if (profile.subregion) { + if (profile.battlegroup) { $WH.ae(s, $WH.ct(LANG.hyphen)); a = $WH.ce('a'); a.className = 'q1'; - a.href = '?profiles=' + profile.region + '.' + profile.subregion; - $WH.ae(a, $WH.ct(profile.subregionname)); + a.href = '?profiles=' + profile.region + '.' + profile.battlegroup; + $WH.ae(a, $WH.ct(profile.battlegroupname)); $WH.ae(s, a); } @@ -15077,8 +15077,8 @@ Listview.templates = { if (profile.region) { buff += ' ' + profile.region; } - if (profile.subregion) { - buff += ' ' + profile.subregion; + if (profile.battlegroup) { + buff += ' ' + profile.battlegroup; } if (profile.realm) { buff += ' ' + profile.realm; @@ -15090,8 +15090,8 @@ Listview.templates = { if (a.region != b.region) { return $WH.strcmp(a.region, b.region); } - if (a.subregion != b.subregion) { - return $WH.strcmp(a.subregion, b.subregion); + if (a.battlegroup != b.battlegroup) { + return $WH.strcmp(a.battlegroup, b.battlegroup); } return $WH.strcmp(a.realm, b.realm); }