Skip to content

Commit

Permalink
Profiler
Browse files Browse the repository at this point in the history
 * further optimize search
   - use achievement 4496 as shortcut for everything based around total achievement points
   - get talent distribution separately
   - get total profiler-items found separately
   - opt to not sort found results
 * fixed Profiles with zero Achievement Points
 * added cache key genrator i forgot :<
 * fixed typos
  • Loading branch information
Sarjuuk committed Mar 29, 2018
1 parent 431e984 commit bf42973
Show file tree
Hide file tree
Showing 49 changed files with 117 additions and 86 deletions.
14 changes: 13 additions & 1 deletion includes/basetype.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,12 +257,24 @@ public function __construct($conditions = [], $miscData = null)

// execute query (finally)
$mtch = 0;
$rows = [];
// 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))
if (key($this->dbNames) === 0)
{
if ($rows = DB::{$n}($dbIdx)->select($query))
{
$mtchQry = preg_replace('/SELECT .*? FROM/', 'SELECT count(1) FROM', $this->queryBase);
$mtch = DB::{$n}($dbIdx)->selectCell($mtchQry);
}
}
else
$rows = DB::{$n}($dbIdx)->SelectPage($mtch, $query);

if ($rows)
{
$this->matches += $mtch;
foreach ($rows as $id => $row)
Expand Down
75 changes: 35 additions & 40 deletions includes/types/profile.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function getListviewData($addInfo = 0, array $reqCols = [])
'talenttree3' => $this->getField('talenttree3'),
'talentspec' => $this->getField('activespec') + 1, // 0 => 1; 1 => 2
'achievementpoints' => $this->getField('achievementpoints'),
'guild' => '$"'.str_replace ('"', '', $this->curTpl['name']).'"', // force this to be a string
'guild' => '$"'.str_replace ('"', '', $this->curTpl['guildname']).'"',// force this to be a string
'guildrank' => $this->getField('guildrank'),
'realm' => Profiler::urlize($this->getField('realmName')),
'realmname' => $this->getField('realmName'),
Expand Down Expand Up @@ -181,7 +181,7 @@ class ProfileListFilter extends Filter

protected $genericFilter = array( // misc (bool): _NUMERIC => useFloat; _STRING => localized; _FLAG => match Value; _BOOLEAN => stringSet
2 => [FILTER_CR_NUMERIC, 'gearscore', NUM_CAST_INT ], // gearscore [num]
3 => [FILTER_CR_NUMERIC, 'achievementpoints', NUM_CAST_INT ], // achievementpoints [num]
3 => [FILTER_CR_CALLBACK, 'cbAchievs', null, null], // achievementpoints [num]
5 => [FILTER_CR_NUMERIC, 'talenttree1', NUM_CAST_INT ], // talenttree1 [num]
6 => [FILTER_CR_NUMERIC, 'talenttree2', NUM_CAST_INT ], // talenttree2 [num]
7 => [FILTER_CR_NUMERIC, 'talenttree3', NUM_CAST_INT ], // talenttree3 [num]
Expand Down Expand Up @@ -245,7 +245,7 @@ public function __construct($fromPOST = false, $opts = [])
parent::__construct($fromPOST, $opts);

if (!empty($this->fiData['c']['cr']))
if (array_intersect($this->fiData['c']['cr'], [2, 3, 5, 6, 7, 21]))
if (array_intersect($this->fiData['c']['cr'], [2, 5, 6, 7, 21]))
$this->useLocalList = true;
}

Expand Down Expand Up @@ -435,16 +435,26 @@ protected function cbTeamRating($cr)

return ['AND', ['at.type', $this->enums[-1][$cr[0]]], ['at.rating', $cr[2], $cr[1]]];
}

protected function cbAchievs($cr)
{
if (!Util::checkNumeric($cr[2], NUM_CAST_INT) || !$this->int2Op($cr[1]))
return false;

if ($this->useLocalList)
return ['p.achievementpoints', $cr[2], $cr[1]];
else
return ['cap.counter', $cr[2], $cr[1]];
}
}


class RemoteProfileList extends ProfileList
{
protected $queryBase = 'SELECT `c`.*, `c`.`guid` AS ARRAY_KEY FROM characters c';
protected $queryOpts = array(
'c' => [['gm', 'g', 'ca', 'ct'], 'g' => 'ARRAY_KEY', 'o' => 'level DESC, name ASC'],
'ca' => ['j' => ['character_achievement ca ON ca.guid = c.guid', true], 's' => ', GROUP_CONCAT(DISTINCT ca.achievement SEPARATOR " ") AS _acvs'],
'ct' => ['j' => ['character_talent ct ON ct.guid = c.guid AND ct.spec = c.activespec', true], 's' => ', GROUP_CONCAT(DISTINCT ct.spell SEPARATOR " ") AS _talents'],
'c' => [['gm', 'g', 'cap']], // 12698: use criteria of Achievement 4496 as shortcut to get total achievement points
'cap' => ['j' => ['character_achievement_progress cap ON cap.guid = c.guid AND cap.criteria = 12698', true], 's' => ', IFNULL(cap.counter, 0) AS achievementpoints'],
'gm' => ['j' => ['guild_member gm ON gm.guid = c.guid', true], 's' => ', gm.rank AS guildrank'],
'g' => ['j' => ['guild g ON g.guildid = gm.guildid', true], 's' => ', g.guildid AS guild, g.name AS guildname'],
'atm' => ['j' => ['arena_team_member atm ON atm.guid = c.guid', true], 's' => ', atm.personalRating AS rating'],
Expand All @@ -466,14 +476,12 @@ public function __construct($conditions = [], $miscData = null)
return;

reset($this->dbNames); // only use when querying single realm
$realmId = key($this->dbNames);
$realms = Profiler::getRealms();
$acvCache = [];
$talentCache = [];
$atCache = [];
$distrib = null;
$talentData = [];
$limit = CFG_SQL_LIMIT_DEFAULT;
$realmId = key($this->dbNames);
$realms = Profiler::getRealms();
$talentSpells = [];
$talentLookup = [];
$distrib = null;
$limit = CFG_SQL_LIMIT_DEFAULT;

foreach ($conditions as $c)
if (is_int($c))
Expand All @@ -486,7 +494,7 @@ public function __construct($conditions = [], $miscData = null)
$curTpl['battlegroup'] = CFG_BATTLEGROUP;

// realm
$r = explode(':', $guid)[0];
list($r, $g) = explode(':', $guid);
if (!empty($realms[$r]))
{
$curTpl['realm'] = $r;
Expand All @@ -503,17 +511,9 @@ public function __construct($conditions = [], $miscData = null)
// temp id
$curTpl['id'] = 0;

// achievement points pre
if ($acvs = explode(' ', $curTpl['_acvs']))
foreach ($acvs as $a)
if ($a && !isset($acvCache[$a]))
$acvCache[$a] = $a;

// talent points pre
if ($talents = explode(' ', $curTpl['_talents']))
foreach ($talents as $t)
if ($t && !isset($talentCache[$t]))
$talentCache[$t] = $t;
$talentLookup[$r][$g] = [];
$talentSpells[] = $curTpl['class'];

// equalize distribution
if ($limit != CFG_SQL_LIMIT_NONE)
Expand All @@ -527,8 +527,10 @@ public function __construct($conditions = [], $miscData = null)
$curTpl['cuFlags'] = 0;
}

if ($talentCache)
$talentData = DB::Aowow()->select('SELECT spell AS ARRAY_KEY, tab, rank FROM ?_talents WHERE spell IN (?a)', $talentCache);
foreach ($talentLookup as $realm => $chars)
$talentLookup[$realm] = DB::Characters($realm)->selectCol('SELECT guid AS ARRAY_KEY, spell AS ARRAY_KEY2, spec FROM character_talent ct WHERE guid IN (?a)', array_keys($chars));

$talentSpells = DB::Aowow()->select('SELECT spell AS ARRAY_KEY, tab, rank FROM ?_talents WHERE class IN (?a)', array_unique($talentSpells));

if ($distrib !== null)
{
Expand All @@ -537,9 +539,6 @@ public function __construct($conditions = [], $miscData = null)
$d = ceil($limit * $d / $total);
}

if ($acvCache)
$acvCache = DB::Aowow()->selectCol('SELECT id AS ARRAY_KEY, points FROM ?_achievement WHERE id IN (?a)', $acvCache);

foreach ($this->iterate() as $guid => &$curTpl)
{
if ($distrib !== null)
Expand All @@ -554,22 +553,18 @@ public function __construct($conditions = [], $miscData = null)
$limit--;
}


$a = explode(' ', $curTpl['_acvs']);
$t = explode(' ', $curTpl['_talents']);
unset($curTpl['_acvs']);
unset($curTpl['_talents']);

// achievement points post
$curTpl['achievementpoints'] = array_sum(array_intersect_key($acvCache, array_combine($a, $a)));
list($r, $g) = explode(':', $guid);

// talent points post
$curTpl['talenttree1'] = 0;
$curTpl['talenttree2'] = 0;
$curTpl['talenttree3'] = 0;
foreach ($talentData as $spell => $data)
if (in_array($spell, $t))
if (!empty($talentLookup[$r][$g]))
{
$talents = array_filter($talentLookup[$r][$g], function($v) use ($curTpl) { return $curTpl['activespec'] == $v; } );
foreach (array_intersect_key($talentSpells, $talents) as $spell => $data)
$curTpl['talenttree'.($data['tab'] + 1)] += $data['rank'];
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion pages/achievement.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
// tabId 0: Database g_initHeader()
class AchievementPage extends GenericPage
{
use DetailPage;
use TrDetailPage;

protected $type = TYPE_ACHIEVEMENT;
protected $typeId = 0;
Expand Down
2 changes: 1 addition & 1 deletion pages/achievements.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// tabId 0: Database g_initHeader()
class AchievementsPage extends GenericPage
{
use ListPage;
use TrListPage;

protected $type = TYPE_ACHIEVEMENT;
protected $tpl = 'achievements';
Expand Down
2 changes: 2 additions & 0 deletions pages/arenateam.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class ArenaTeamPage extends GenericPage

protected $lvTabs = [];

protected $type = TYPE_ARENA_TEAM;

protected $tabId = 1;
protected $path = [1, 5, 3];
protected $tpl = 'roster';
Expand Down
2 changes: 2 additions & 0 deletions pages/arenateams.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class ArenaTeamsPage extends GenericPage
{
use TrProfiler;

protected $type = TYPE_ARENA_TEAM;

protected $tabId = 1;
protected $path = [1, 5, 3];
protected $tpl = 'arena-teams';
Expand Down
2 changes: 1 addition & 1 deletion pages/class.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// tabId 0: Database g_initHeader()
class ClassPage extends GenericPage
{
use DetailPage;
use TrDetailPage;

protected $type = TYPE_CLASS;
protected $typeId = 0;
Expand Down
2 changes: 1 addition & 1 deletion pages/classes.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// tabId 0: Database g_initHeader()
class ClassesPage extends GenericPage
{
use ListPage;
use TrListPage;

protected $type = TYPE_CLASS;
protected $tpl = 'list-page-generic';
Expand Down
2 changes: 1 addition & 1 deletion pages/currencies.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// tabId 0: Database g_initHeader()
class CurrenciesPage extends GenericPage
{
use ListPage;
use TrListPage;

protected $type = TYPE_CURRENCY;
protected $tpl = 'list-page-generic';
Expand Down
2 changes: 1 addition & 1 deletion pages/currency.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// tabId 0: Database g_initHeader()
class CurrencyPage extends GenericPage
{
use DetailPage;
use TrDetailPage;

protected $type = TYPE_CURRENCY;
protected $typeId = 0;
Expand Down
2 changes: 1 addition & 1 deletion pages/emote.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// tabid 0: Database g_initHeader()
class EmotePage extends GenericPage
{
use DetailPage;
use TrDetailPage;

protected $type = TYPE_EMOTE;
protected $typeId = 0;
Expand Down
2 changes: 1 addition & 1 deletion pages/emotes.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// tabid 0: Database g_initHeader()
class EmotesPage extends GenericPage
{
use ListPage;
use TrListPage;

protected $type = TYPE_EMOTE;
protected $tpl = 'list-page-generic';
Expand Down
2 changes: 1 addition & 1 deletion pages/enchantment.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// tabId 0: Database g_initHeader()
class EnchantmentPage extends GenericPage
{
use DetailPage;
use TrDetailPage;

protected $type = TYPE_ENCHANTMENT;
protected $typeId = 0;
Expand Down
2 changes: 1 addition & 1 deletion pages/enchantments.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// tabId 0: Database g_initHeader()
class EnchantmentsPage extends GenericPage
{
use ListPage;
use TrListPage;

protected $type = TYPE_ENCHANTMENT;
protected $tpl = 'enchantments';
Expand Down
2 changes: 1 addition & 1 deletion pages/event.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// tabId 0: Database g_initHeader()
class EventPage extends GenericPage
{
use DetailPage;
use TrDetailPage;

protected $type = TYPE_WORLDEVENT;
protected $typeId = 0;
Expand Down
2 changes: 1 addition & 1 deletion pages/events.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// tabId 0: Database g_initHeader()
class EventsPage extends GenericPage
{
use ListPage;
use TrListPage;

protected $type = TYPE_WORLDEVENT;
protected $tpl = 'list-page-generic';
Expand Down
2 changes: 1 addition & 1 deletion pages/faction.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// tabId 0: Database g_initHeader()
class FactionPage extends GenericPage
{
use DetailPage;
use TrDetailPage;

protected $type = TYPE_FACTION;
protected $typeId = 0;
Expand Down
2 changes: 1 addition & 1 deletion pages/factions.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// tabId 0: Database g_initHeader()
class FactionsPage extends GenericPage
{
use ListPage;
use TrListPage;

protected $type = TYPE_FACTION;
protected $tpl = 'list-page-generic';
Expand Down
14 changes: 12 additions & 2 deletions pages/genericPage.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
die('illegal access');


trait DetailPage
trait TrDetailPage
{
protected $hasComContent = true;
protected $category = null; // not used on detail pages
Expand Down Expand Up @@ -48,7 +48,7 @@ protected function applyCCErrors()
}


trait ListPage
trait TrListPage
{
protected $category = null;
protected $filter = [];
Expand Down Expand Up @@ -85,6 +85,16 @@ trait TrProfiler

protected $doResync = null;

protected function generateCacheKey($withStaff = true)
{
$staff = intVal($withStaff && User::isInGroup(U_GROUP_EMPLOYEE));

// mode, type, typeId, employee-flag, localeId, category, filter
$key = [$this->mode, $this->type, $this->subject->getField('id'), $staff, User::$localeId, '-1', '-1'];

return implode('_', $key);
}

protected function getSubjectFromUrl($str)
{
if (!$str)
Expand Down
2 changes: 2 additions & 0 deletions pages/guild.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class GuildPage extends GenericPage

protected $lvTabs = [];

protected $type = TYPE_GUILD;

protected $tabId = 1;
protected $path = [1, 5, 2];
protected $tpl = 'roster';
Expand Down
2 changes: 2 additions & 0 deletions pages/guilds.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class GuildsPage extends GenericPage
{
use TrProfiler;

protected $type = TYPE_GUILD;

protected $tabId = 1;
protected $path = [1, 5, 2];
protected $tpl = 'guilds';
Expand Down
2 changes: 1 addition & 1 deletion pages/icon.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// tabId 0: Database g_initHeader()
class IconPage extends GenericPage
{
use DetailPage;
use TrDetailPage;

protected $type = TYPE_ICON;
protected $typeId = 0;
Expand Down
2 changes: 1 addition & 1 deletion pages/icons.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// tabId 0: Database g_initHeader()
class IconsPage extends GenericPage
{
use ListPage;
use TrListPage;

protected $type = TYPE_ICON;
protected $tpl = 'icons';
Expand Down
Loading

0 comments on commit bf42973

Please sign in to comment.