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
$limit = Cfg::get('SQL_LIMIT_DEFAULT');
foreach ($conditions as $c)
if (is_int($c))
$limit = $c;
$limit ??= Cfg::get('SQL_LIMIT_DEFAULT');
if (!$limit) // int:0 means unlimited, so skip early
return;
$total = array_sum($distrib);
foreach ($distrib as &$d)
$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 = [];
// init members for tooltips
foreach ($this->members as $realmId => $teams)
@@ -356,8 +362,6 @@ class LocalArenaTeamList extends ArenaTeamList
if ($this->error)
return;
$realms = Profiler::getRealms();
// post processing
$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"

View File

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

View File

@@ -534,12 +534,7 @@ class RemoteProfileList extends ProfileList
$realms = Profiler::getRealms();
$talentSpells = [];
$talentLookup = [];
$distrib = null;
$limit = Cfg::get('SQL_LIMIT_DEFAULT');
foreach ($conditions as $c)
if (is_int($c))
$limit = $c;
$distrib = [];
// post processing
foreach ($this->iterate() as $guid => &$curTpl)
@@ -579,13 +574,10 @@ class RemoteProfileList extends ProfileList
$curTpl['activespec'] = $curTpl['activeTalentGroup'];
// equalize distribution
if ($limit != Cfg::get('SQL_LIMIT_NONE'))
{
if (empty($distrib[$curTpl['realm']]))
$distrib[$curTpl['realm']] = 1;
else
$distrib[$curTpl['realm']]++;
}
if (empty($distrib[$curTpl['realm']]))
$distrib[$curTpl['realm']] = 1;
else
$distrib[$curTpl['realm']]++;
// char is pending rename
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));
if ($distrib !== null)
{
$total = array_sum($distrib);
foreach ($distrib as &$d)
$d = ceil($limit * $d / $total);
}
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);
foreach ($distrib as &$d)
$d = ceil($limit * $d / $total);
foreach ($this->iterate() as $guid => &$curTpl)
{
if ($distrib !== null)
if ($distrib)
{
if ($limit <= 0 || $distrib[$curTpl['realm']] <= 0)
{

View File

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