Profiler/Optimization

* move searchable flags to their own db cols to speed up lookups
 * don't cast profile name to LOWER in SQL when displaying tooltips.
This commit is contained in:
Sarjuuk
2025-11-08 21:06:03 +01:00
parent 8a169eb400
commit 6eb5a67add
23 changed files with 92 additions and 58 deletions

View File

@@ -503,7 +503,7 @@ class Profiler
// char is flagged for rename
if ($char['at_login'] & 0x1)
{
$ri = DB::Aowow()->selectCell('SELECT MAX(`renameItr`) FROM ?_profiler_profiles WHERE `realm` = ?d AND `realmGUID` IS NOT NULL AND `name` = ?', $realmId, $char['name']);
$ri = DB::Aowow()->selectCell('SELECT MAX(`renameItr`) FROM ?_profiler_profiles WHERE `realm` = ?d AND `custom` = 0 AND `name` = ?', $realmId, $char['name']);
$data['renameItr'] = $ri ? ++$ri : 1;
}
@@ -827,7 +827,7 @@ class Profiler
'realmGUID' => $guild['id'],
'name' => $guild['name'],
'nameUrl' => self::urlize($guild['name']),
'cuFlags' => PROFILER_CU_NEEDS_RESYNC
'stub' => 1
);
$guildId = DB::Aowow()->query('INSERT IGNORE INTO ?_profiler_guild (?#) VALUES (?a)', array_keys($gData), array_values($gData));
@@ -853,7 +853,7 @@ class Profiler
'name' => $t['name'],
'nameUrl' => self::urlize($t['name']),
'type' => $t['type'],
'cuFlags' => PROFILER_CU_NEEDS_RESYNC
'stub' => 1
);
$teamId = DB::Aowow()->query('INSERT IGNORE INTO ?_profiler_arena_team (?#) VALUES (?a)', array_keys($team), array_values($team));
@@ -889,7 +889,7 @@ class Profiler
/*********************/
if (DB::Aowow()->query('UPDATE ?_profiler_profiles SET ?a WHERE `realm` = ?d AND `realmGUID` = ?d', $data, $realmId, $charGuid) !== null)
DB::Aowow()->query('UPDATE ?_profiler_profiles SET `cuFlags` = `cuFlags` & ?d WHERE `id` = ?d', ~PROFILER_CU_NEEDS_RESYNC, $profileId);
DB::Aowow()->query('UPDATE ?_profiler_profiles SET `stub` = 0 WHERE `id` = ?d', $profileId);
return true;
}
@@ -956,7 +956,7 @@ class Profiler
/* mark guild as done */
/*********************/
DB::Aowow()->query('UPDATE ?_profiler_guild SET `cuFlags` = `cuFlags` & ?d WHERE `id` = ?d', ~PROFILER_CU_NEEDS_RESYNC, $guildId);
DB::Aowow()->query('UPDATE ?_profiler_guild SET `stub` = 0 WHERE `id` = ?d', $guildId);
return true;
}
@@ -1056,7 +1056,7 @@ class Profiler
/* mark team as done */
/*********************/
DB::Aowow()->query('UPDATE ?_profiler_arena_team SET `cuFlags` = `cuFlags` & ?d WHERE `id` = ?d', ~PROFILER_CU_NEEDS_RESYNC, $teamId);
DB::Aowow()->query('UPDATE ?_profiler_arena_team SET `stub` = 0 WHERE `id` = ?d', $teamId);
return true;
}

View File

@@ -235,7 +235,7 @@ class RemoteArenaTeamList extends ArenaTeamList
'nameUrl' => Profiler::urlize($this->getField('name')),
'type' => $this->getField('type'),
'rating' => $this->getField('rating'),
'cuFlags' => PROFILER_CU_NEEDS_RESYNC
'stub' => 1
);
}

View File

@@ -48,18 +48,16 @@ class GuildList extends DBTypeList
if (!$guilds)
return;
$stats = DB::Aowow()->select('SELECT `guild` AS ARRAY_KEY, `id` AS ARRAY_KEY2, `level`, `gearscore`, `achievementpoints`, IF(`cuFlags` & ?d, 0, 1) AS "synced" FROM ?_profiler_profiles WHERE `guild` IN (?a) ORDER BY `gearscore` DESC', PROFILER_CU_NEEDS_RESYNC, $guilds);
$stats = DB::Aowow()->select('SELECT `guild` AS ARRAY_KEY, `id` AS ARRAY_KEY2, `level`, `gearscore`, `achievementpoints` FROM ?_profiler_profiles WHERE `guild` IN (?a) AND `stub` = 0 ORDER BY `gearscore` DESC', $guilds);
foreach ($this->iterate() as &$_curTpl)
{
$id = $_curTpl['id'];
if (empty($stats[$id]))
continue;
$guildStats = array_filter($stats[$id], function ($x) { return $x['synced']; } );
if (!$guildStats)
continue;
$guildStats = $stats[$id];
$nMaxLevel = count(array_filter($stats[$id], function ($x) { return $x['level'] >= MAX_LEVEL; } ));
$nMaxLevel = count(array_filter($stats[$id], fn($x) => $x['level'] >= MAX_LEVEL));
$levelMod = 1.0;
if ($nMaxLevel < 25)
@@ -227,7 +225,7 @@ class RemoteGuildList extends GuildList
'realmGUID' => $this->getField('guildid'),
'name' => $this->getField('name'),
'nameUrl' => Profiler::urlize($this->getField('name')),
'cuFlags' => PROFILER_CU_NEEDS_RESYNC
'stub' => 1
);
}

View File

@@ -83,7 +83,7 @@ class ProfileList extends DBTypeList
if ($this->getField('cuFlags') & PROFILER_CU_PINNED)
$data[$this->id]['pinned'] = 1;
if ($this->getField('cuFlags') & PROFILER_CU_DELETED)
if ($this->getField('deleted'))
$data[$this->id]['deleted'] = 1;
}
@@ -168,7 +168,7 @@ class ProfileList extends DBTypeList
public function isCustom() : bool
{
return $this->getField('cuFlags') & PROFILER_CU_PROFILE;
return $this->getField('custom');
}
public function isVisibleToUser() : bool
@@ -176,7 +176,7 @@ class ProfileList extends DBTypeList
if (!$this->isCustom() || User::isInGroup(U_GROUP_ADMIN | U_GROUP_BUREAU))
return true;
if ($this->getField('cuFlags') & PROFILER_CU_DELETED)
if ($this->getField('deleted'))
return false;
if (User::$id == $this->getField('user'))
@@ -515,7 +515,7 @@ class RemoteProfileList extends ProfileList
if ($curTpl['at_login'] & 0x1)
{
if (!isset($this->rnItr[$curTpl['name']]))
$this->rnItr[$curTpl['name']] = DB::Aowow()->selectCell('SELECT MAX(`renameItr`) FROM ?_profiler_profiles WHERE `realm` = ?d AND `realmGUID` IS NOT NULL AND `name` = ?', $r, $curTpl['name']) ?: 0;
$this->rnItr[$curTpl['name']] = DB::Aowow()->selectCell('SELECT MAX(`renameItr`) FROM ?_profiler_profiles WHERE `realm` = ?d AND `custom` = 0 AND `name` = ?', $r, $curTpl['name']) ?: 0;
// already saved as "pending rename"
if ($rnItr = DB::Aowow()->selectCell('SELECT `renameItr` FROM ?_profiler_profiles WHERE `realm` = ?d AND `realmGUID` = ?d', $r, $g))
@@ -606,7 +606,7 @@ class RemoteProfileList extends ProfileList
'gender' => $this->getField('gender'),
'guild' => $guildGUID ?: null,
'guildrank' => $guildGUID ? $this->getField('guildrank') : null,
'cuFlags' => PROFILER_CU_NEEDS_RESYNC
'stub' => 1
);
if ($guildGUID && empty($guildData[$realmId.'-'.$guildGUID]))
@@ -615,7 +615,7 @@ class RemoteProfileList extends ProfileList
'realmGUID' => $guildGUID,
'name' => $this->getField('guildname'),
'nameUrl' => Profiler::urlize($this->getField('guildname')),
'cuFlags' => PROFILER_CU_NEEDS_RESYNC
'stub' => 1
);
}
@@ -643,8 +643,7 @@ class RemoteProfileList extends ProfileList
// merge back local ids
$localIds = DB::Aowow()->select(
'SELECT CONCAT(`realm`, ":", `realmGUID`) AS ARRAY_KEY, `id`, `gearscore` FROM ?_profiler_profiles WHERE (`cuFlags` & ?d) = 0 AND `realm` IN (?a) AND `realmGUID` IN (?a)',
PROFILER_CU_PROFILE,
'SELECT CONCAT(`realm`, ":", `realmGUID`) AS ARRAY_KEY, `id`, `gearscore` FROM ?_profiler_profiles WHERE `custom` = 0 AND `realm` IN (?a) AND `realmGUID` IN (?a)',
array_column($baseData, 'realm'),
array_column($baseData, 'realmGUID')
);

View File

@@ -374,9 +374,9 @@ define('QUEST_CU_PART_OF_SERIES', 0x0200);
define('PROFILER_CU_PUBLISHED', 0x01);
define('PROFILER_CU_PINNED', 0x02);
define('PROFILER_CU_DELETED', 0x04);
define('PROFILER_CU_PROFILE', 0x08);
define('PROFILER_CU_NEEDS_RESYNC', 0x10);
// define('PROFILER_CU_DELETED', 0x04); // migrated to separate db cols
// define('PROFILER_CU_PROFILE', 0x08);
// define('PROFILER_CU_NEEDS_RESYNC', 0x10);
define('GUIDE_CU_NO_QUICKFACTS', 0x100); // merge with CC_FLAG_*
define('GUIDE_CU_NO_RATING', 0x200);

View File

@@ -785,7 +785,7 @@ class User
// the old approach ['OR', ['user', self::$id], ['ap.accountId', self::$id]] caused keys to not get used
$conditions = $ap ? [['OR', ['user', self::$id], ['id', $ap]]] : ['user', self::$id];
if (!self::isInGroup(U_GROUP_ADMIN | U_GROUP_BUREAU))
$conditions[] = [['cuFlags', PROFILER_CU_DELETED, '&'], 0];
$conditions[] = ['deleted', 0];
self::$profiles = (new LocalProfileList($conditions));
}