Misc/Fixup

* test arrays first before use, not the other way round
 * do not try to init local arena team entries if there are no entries in list.
 * fix equally distributing chars/guilds/arenateams across realms for unlimited (0) lists
 * fix double declaration of realms in ArenateamList
This commit is contained in:
Sarjuuk
2025-06-03 16:00:02 +02:00
parent ee02e70571
commit c3048fe1f8
4 changed files with 32 additions and 28 deletions

View File

@@ -212,11 +212,14 @@ class RemoteArenaTeamList extends ArenaTeamList
); );
// equalize subject distribution across realms // equalize subject distribution across realms
$limit = Cfg::get('SQL_LIMIT_DEFAULT');
foreach ($conditions as $c) foreach ($conditions as $c)
if (is_int($c)) if (is_int($c))
$limit = $c; $limit = $c;
$limit ??= Cfg::get('SQL_LIMIT_DEFAULT');
if (!$limit) // int:0 means unlimited, so skip early
return;
$total = array_sum($distrib); $total = array_sum($distrib);
foreach ($distrib as &$d) foreach ($distrib as &$d)
$d = ceil($limit * $d / $total); $d = ceil($limit * $d / $total);
@@ -238,8 +241,11 @@ class RemoteArenaTeamList extends ArenaTeamList
} }
} }
public function initializeLocalEntries() public function initializeLocalEntries() : void
{ {
if (!$this->templates)
return;
$profiles = []; $profiles = [];
// init members for tooltips // init members for tooltips
foreach ($this->members as $realmId => $teams) foreach ($this->members as $realmId => $teams)
@@ -356,8 +362,6 @@ class LocalArenaTeamList extends ArenaTeamList
if ($this->error) if ($this->error)
return; return;
$realms = Profiler::getRealms();
// post processing // post processing
$members = DB::Aowow()->select( $members = DB::Aowow()->select(
'SELECT `arenaTeamId` AS ARRAY_KEY, p.`id` AS ARRAY_KEY2, p.`name` AS "0", p.`class` AS "1", atm.`captain` AS "2" 'SELECT `arenaTeamId` AS ARRAY_KEY, p.`id` AS ARRAY_KEY2, p.`name` AS "0", p.`class` AS "1", atm.`captain` AS "2"

View File

@@ -217,11 +217,14 @@ class RemoteGuildList extends GuildList
$distrib[$curTpl['realm']]++; $distrib[$curTpl['realm']]++;
} }
$limit = Cfg::get('SQL_LIMIT_DEFAULT');
foreach ($conditions as $c) foreach ($conditions as $c)
if (is_int($c)) if (is_int($c))
$limit = $c; $limit = $c;
$limit ??= Cfg::get('SQL_LIMIT_DEFAULT');
if (!$limit) // int:0 means unlimited, so skip early
return;
$total = array_sum($distrib); $total = array_sum($distrib);
foreach ($distrib as &$d) foreach ($distrib as &$d)
$d = ceil($limit * $d / $total); $d = ceil($limit * $d / $total);

View File

@@ -534,12 +534,7 @@ class RemoteProfileList extends ProfileList
$realms = Profiler::getRealms(); $realms = Profiler::getRealms();
$talentSpells = []; $talentSpells = [];
$talentLookup = []; $talentLookup = [];
$distrib = null; $distrib = [];
$limit = Cfg::get('SQL_LIMIT_DEFAULT');
foreach ($conditions as $c)
if (is_int($c))
$limit = $c;
// post processing // post processing
foreach ($this->iterate() as $guid => &$curTpl) foreach ($this->iterate() as $guid => &$curTpl)
@@ -579,13 +574,10 @@ class RemoteProfileList extends ProfileList
$curTpl['activespec'] = $curTpl['activeTalentGroup']; $curTpl['activespec'] = $curTpl['activeTalentGroup'];
// equalize distribution // equalize distribution
if ($limit != Cfg::get('SQL_LIMIT_NONE'))
{
if (empty($distrib[$curTpl['realm']])) if (empty($distrib[$curTpl['realm']]))
$distrib[$curTpl['realm']] = 1; $distrib[$curTpl['realm']] = 1;
else else
$distrib[$curTpl['realm']]++; $distrib[$curTpl['realm']]++;
}
// char is pending rename // char is pending rename
if ($curTpl['at_login'] & 0x1) if ($curTpl['at_login'] & 0x1)
@@ -611,16 +603,21 @@ class RemoteProfileList extends ProfileList
$talentSpells = DB::Aowow()->select('SELECT spell AS ARRAY_KEY, tab, `rank` FROM ?_talents WHERE class IN (?a)', array_unique($talentSpells)); $talentSpells = DB::Aowow()->select('SELECT spell AS ARRAY_KEY, tab, `rank` FROM ?_talents WHERE class IN (?a)', array_unique($talentSpells));
if ($distrib !== null) foreach ($conditions as $c)
{ if (is_int($c))
$limit = $c;
$limit ??= Cfg::get('SQL_LIMIT_DEFAULT');
if (!$limit) // int:0 means unlimited, so skip process
$distrib = [];
$total = array_sum($distrib); $total = array_sum($distrib);
foreach ($distrib as &$d) foreach ($distrib as &$d)
$d = ceil($limit * $d / $total); $d = ceil($limit * $d / $total);
}
foreach ($this->iterate() as $guid => &$curTpl) foreach ($this->iterate() as $guid => &$curTpl)
{ {
if ($distrib !== null) if ($distrib)
{ {
if ($limit <= 0 || $distrib[$curTpl['realm']] <= 0) if ($limit <= 0 || $distrib[$curTpl['realm']] <= 0)
{ {

View File

@@ -829,14 +829,14 @@ abstract class Util
public static function createSqlBatchInsert(array $data) : array public static function createSqlBatchInsert(array $data) : array
{ {
if (!count($data) || !is_array(reset($data)))
return [];
$nRows = 100; $nRows = 100;
$nItems = count(reset($data)); $nItems = count(reset($data));
$result = []; $result = [];
$buff = []; $buff = [];
if (!count($data))
return [];
foreach ($data as $d) foreach ($data as $d)
{ {
if (count($d) != $nItems) if (count($d) != $nItems)