From c3048fe1f829be0f60d1bef2883f89ac241da038 Mon Sep 17 00:00:00 2001 From: Sarjuuk Date: Tue, 3 Jun 2025 16:00:02 +0200 Subject: [PATCH] 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 --- includes/types/arenateam.class.php | 12 ++++++---- includes/types/guild.class.php | 5 +++- includes/types/profile.class.php | 37 ++++++++++++++---------------- includes/utilities.php | 6 ++--- 4 files changed, 32 insertions(+), 28 deletions(-) diff --git a/includes/types/arenateam.class.php b/includes/types/arenateam.class.php index 49bd77a2..d3fec387 100644 --- a/includes/types/arenateam.class.php +++ b/includes/types/arenateam.class.php @@ -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" diff --git a/includes/types/guild.class.php b/includes/types/guild.class.php index b897c4ef..4ad7cedb 100644 --- a/includes/types/guild.class.php +++ b/includes/types/guild.class.php @@ -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); diff --git a/includes/types/profile.class.php b/includes/types/profile.class.php index 2dd2938c..10f8b51f 100644 --- a/includes/types/profile.class.php +++ b/includes/types/profile.class.php @@ -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) { diff --git a/includes/utilities.php b/includes/utilities.php index a7dab46a..cee07a57 100644 --- a/includes/utilities.php +++ b/includes/utilities.php @@ -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)