diff --git a/GameEngine/Automation.php b/GameEngine/Automation.php index 3fac173c..f4fdfca5 100755 --- a/GameEngine/Automation.php +++ b/GameEngine/Automation.php @@ -4260,7 +4260,9 @@ class Automation { foreach($trainlist as $train){ $vilIDs[$train['vref']] = true; } - $database->getProfileVillages(array_keys($vilIDs), 5); + $vilIDs = array_keys($vilIDs); + $database->getProfileVillages($vilIDs, 5); + $database->cacheResourceLevels($vilIDs); // calculate training updates foreach($trainlist as $train){ @@ -5223,6 +5225,14 @@ class Automation { if ($q['Total'] > 0) { $villages = $database->getVillagesID2($leader); $max = 0; + + // cache resource levels + $vilIDs = []; + foreach($villages as $village){ + $vilIDs[$village['wref']] = true; + } + $database->cacheResourceLevels(array_keys($vilIDs)); + foreach($villages as $village){ $field = $database->getResourceLevel($village['wref'], false); for($i=19;$i<=40;$i++){ diff --git a/GameEngine/Database.php b/GameEngine/Database.php index 965538e3..e8ad4457 100755 --- a/GameEngine/Database.php +++ b/GameEngine/Database.php @@ -2073,6 +2073,36 @@ class MYSQLi_DB implements IDbConnection { return mysqli_query($this->dblink,$q); } + function cacheResourceLevels($vids) { + if (!is_array($vids)) { + $vids = [$vids]; + } + + $newVids = []; + foreach ($vids as $index => $vidValue) { + $vids[ $index ] = (int) $vidValue; + + // don't cache what's cached + if (!isset(self::$resourceLevelsCache[$vids[ $index ]])) { + $newVids[] = $vids[ $index ]; + } + } + $vids = $newVids; + + if (!count($vids)) { + return []; + } + + $q = "SELECT * FROM " . TB_PREFIX . "fdata WHERE vref IN(".implode(', ', $vids).")"; + $result = mysqli_query($this->dblink,$q); + + foreach ( $this->mysqli_fetch_all( $result ) as $row ) { + self::$resourceLevelsCache[ $row['vref'] ] = $row; + } + + return self::$resourceLevelsCache; + } + function getResourceLevel($vid, $use_cache = true) { list($vid) = $this->escape_input((int) $vid); diff --git a/GameEngine/Village.php b/GameEngine/Village.php index edbfd92b..efb0c9bf 100755 --- a/GameEngine/Village.php +++ b/GameEngine/Village.php @@ -46,6 +46,7 @@ class Village { } $this->LoadTown(); + $database->cacheResourceLevels($this->wid); $this->calculateProduction(); $this->processProduction(); $this->ActionControl();