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)
This commit is contained in:
Sarjuuk
2015-08-11 14:44:55 +02:00
parent bd2e0ccada
commit 11584a68d6
10 changed files with 137 additions and 41 deletions

View File

@@ -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?

View File

@@ -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;
}
}
?>

View File

@@ -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`
--

View File

@@ -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],

View File

@@ -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);
}

View File

@@ -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';

View File

@@ -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],

View File

@@ -0,0 +1,26 @@
<?php
if (!defined('AOWOW_REVISION'))
die('illegal access');
if (!CLI)
die('not in cli mode');
$customData = array(
);
$reqDBC = ['talent', 'talenttab'];
function talents()
{
// class: 0 => 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;
}
?>

View File

@@ -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');

View File

@@ -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);
}