mirror of
https://github.com/Shadowss/TravianZ.git
synced 2026-08-28 14:17:15 +00:00
refactor: multiple calls to getVSumField() replaced by a single one
#313
This commit is contained in:
@@ -16,10 +16,17 @@ if($_GET['aid'])
|
|||||||
$aliusers = $database->getAllMember($_GET['aid']);
|
$aliusers = $database->getAllMember($_GET['aid']);
|
||||||
if($alidata and $aliusers)
|
if($alidata and $aliusers)
|
||||||
{
|
{
|
||||||
foreach($aliusers as $member)
|
$memberIDs = [];
|
||||||
{
|
foreach($aliusers as $member) {
|
||||||
$totalpop += $database->getVSumField($member['id'],"pop");
|
$memberIDs[] = $member['id'];
|
||||||
} ?>
|
}
|
||||||
|
$data = $database->getVSumField($memberIDs,"pop");
|
||||||
|
|
||||||
|
if (count($data)) {
|
||||||
|
foreach ($data as $row) {
|
||||||
|
$totalpop += $row['Total'];
|
||||||
|
}
|
||||||
|
} ?>
|
||||||
|
|
||||||
<br>
|
<br>
|
||||||
<table id="profile" cellpadding="1" cellspacing="1">
|
<table id="profile" cellpadding="1" cellspacing="1">
|
||||||
|
|||||||
@@ -5250,9 +5250,19 @@ class Automation {
|
|||||||
$ally = $database->getAlliance($aid);
|
$ally = $database->getAlliance($aid);
|
||||||
$memberlist = $database->getAllMember($ally['id']);
|
$memberlist = $database->getAllMember($ally['id']);
|
||||||
$oldrank = 0;
|
$oldrank = 0;
|
||||||
|
|
||||||
|
$memberIDs = [];
|
||||||
foreach($memberlist as $member) {
|
foreach($memberlist as $member) {
|
||||||
$oldrank += $database->getVSumField($member['id'],"pop");
|
$memberIDs[] = $member['id'];
|
||||||
}
|
}
|
||||||
|
$data = $database->getVSumField($memberIDs,"pop");
|
||||||
|
|
||||||
|
if (count($data)) {
|
||||||
|
foreach ($data as $row) {
|
||||||
|
$oldrank += $row['Total'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if($ally['oldrank'] != $oldrank){
|
if($ally['oldrank'] != $oldrank){
|
||||||
if($ally['oldrank'] < $oldrank) {
|
if($ally['oldrank'] < $oldrank) {
|
||||||
$totalpoints = $oldrank - $ally['oldrank'];
|
$totalpoints = $oldrank - $ally['oldrank'];
|
||||||
|
|||||||
+49
-10
@@ -1770,6 +1770,11 @@ class MYSQLi_DB implements IDbConnection {
|
|||||||
$uid = $newIDs;
|
$uid = $newIDs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// nothing left to cache, return the full cache
|
||||||
|
if (!count($uid)) {
|
||||||
|
return self::$userVillagesCache;
|
||||||
|
}
|
||||||
|
|
||||||
switch ($mode) {
|
switch ($mode) {
|
||||||
// by owner ID
|
// by owner ID
|
||||||
case 0: $q = "SELECT * FROM " . TB_PREFIX . "vdata WHERE owner IN(".implode(', ', $uid).") ORDER BY capital DESC,pop DESC";
|
case 0: $q = "SELECT * FROM " . TB_PREFIX . "vdata WHERE owner IN(".implode(', ', $uid).") ORDER BY capital DESC,pop DESC";
|
||||||
@@ -2910,9 +2915,20 @@ class MYSQLi_DB implements IDbConnection {
|
|||||||
$ally = $this->getAlliance($aid);
|
$ally = $this->getAlliance($aid);
|
||||||
$memberlist = $this->getAllMember($ally['id']);
|
$memberlist = $this->getAllMember($ally['id']);
|
||||||
$oldrank = 0;
|
$oldrank = 0;
|
||||||
foreach($memberlist as $member) {
|
$memberIDs = [];
|
||||||
$oldrank += $this->getVSumField($member['id'],"pop");
|
|
||||||
}
|
foreach($memberlist as $member) {
|
||||||
|
$memberIDs[] = $member['id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = $this->getVSumField($memberIDs,"pop");
|
||||||
|
|
||||||
|
if (count($data)) {
|
||||||
|
foreach ($data as $row) {
|
||||||
|
$oldrank += $row['Total'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if($ally['oldrank'] != $oldrank){
|
if($ally['oldrank'] != $oldrank){
|
||||||
if($ally['oldrank'] < $oldrank) {
|
if($ally['oldrank'] < $oldrank) {
|
||||||
$totalpoints = $oldrank - $ally['oldrank'];
|
$totalpoints = $oldrank - $ally['oldrank'];
|
||||||
@@ -3824,7 +3840,7 @@ class MYSQLi_DB implements IDbConnection {
|
|||||||
lastupdate < (UNIX_TIMESTAMP() - 600)
|
lastupdate < (UNIX_TIMESTAMP() - 600)
|
||||||
"; // recount every 10 minutes
|
"; // recount every 10 minutes
|
||||||
|
|
||||||
mysqli_query($this->dblink, $q) OR DIE ($q);
|
mysqli_query($this->dblink, $q);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getVSumField($uid, $field, $use_cache = true) {
|
function getVSumField($uid, $field, $use_cache = true) {
|
||||||
@@ -7038,15 +7054,38 @@ References: User ID/Message ID, Mode
|
|||||||
|
|
||||||
// first of all, check if we should be using cache and whether the field
|
// first of all, check if we should be using cache and whether the field
|
||||||
// required is already cached
|
// required is already cached
|
||||||
if ($use_cache && ($cachedValue = self::returnCachedContent(self::$foolArtefactCache, $type.$vid.$uid)) && !is_null($cachedValue)) {
|
if ($use_cache && isset(self::$foolArtefactCache[$vid]) && is_array(self::$foolArtefactCache[$vid]) && !count(self::$foolArtefactCache[$vid])) {
|
||||||
return $cachedValue;
|
return [];
|
||||||
|
} else if ($use_cache && ($cachedValue = self::returnCachedContent(self::$foolArtefactCache, $vid)) && !is_null($cachedValue)) {
|
||||||
|
$data = [];
|
||||||
|
// prepare the data as requested
|
||||||
|
if (isset($cachedValue[$type.$uid])) {
|
||||||
|
foreach ($cachedValue[$type.$uid] as $row) {
|
||||||
|
if ($row['type'] == 8 && $row['kind'] == $type && $row['owner'] == $uid && $row['size'] > 1 && $row['active'] > 1) {
|
||||||
|
$data[] = $row;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
$q = "SELECT * FROM " . TB_PREFIX . "artefacts WHERE vref = $vid AND ((type = 8 AND kind = $type) OR (owner = $uid AND size > 1 AND active = 1 AND type = 8 AND kind = $type))";
|
$q = "SELECT * FROM " . TB_PREFIX . "artefacts WHERE vref = $vid"; //" AND ((type = 8 AND kind = $type) OR (owner = $uid AND size > 1 AND active = 1 AND type = 8 AND kind = $type))";
|
||||||
$result = mysqli_query($this->dblink,$q);
|
$result = $this->mysqli_fetch_all(mysqli_query($this->dblink,$q));
|
||||||
|
|
||||||
self::$foolArtefactCache[$type.$vid.$uid] = $this->mysqli_fetch_all($result);
|
// cache all types and return the requested one
|
||||||
return self::$foolArtefactCache[$type.$vid.$uid];
|
if (count($result)) {
|
||||||
|
foreach ($result as $arteInfo) {
|
||||||
|
if (!isset(self::$foolArtefactCache[$vid][$arteInfo['type'].$arteInfo['owner']])) {
|
||||||
|
self::$foolArtefactCache[$vid][$arteInfo['type'].$arteInfo['owner']] = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
self::$foolArtefactCache[$vid][$arteInfo['type'].$arteInfo['owner']][] = $arteInfo;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
self::$foolArtefactCache[$vid] = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
return (isset(self::$foolArtefactCache[$vid][$type.$uid]) ? self::$foolArtefactCache[$vid][$type.$uid] : []);
|
||||||
}
|
}
|
||||||
|
|
||||||
function claimArtefact($vref, $ovref, $id) {
|
function claimArtefact($vref, $ovref, $id) {
|
||||||
|
|||||||
+14
-4
@@ -474,16 +474,26 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function procARankArray() {
|
public function procARankArray() {
|
||||||
global $multisort;
|
global $multisort, $database;
|
||||||
$array = $GLOBALS['db']->getARanking();
|
$array = $GLOBALS['db']->getARanking();
|
||||||
$holder = array();
|
$holder = array();
|
||||||
|
|
||||||
foreach($array as $value) {
|
foreach($array as $value) {
|
||||||
$memberlist = $GLOBALS['db']->getAllMember($value['id']);
|
$memberlist = $GLOBALS['db']->getAllMember($value['id']);
|
||||||
$totalpop = 0;
|
$totalpop = 0;
|
||||||
foreach($memberlist as $member) {
|
|
||||||
$totalpop += $GLOBALS['db']->getVSumField($member['id'], "pop");
|
$memberIDs = [];
|
||||||
}
|
foreach($memberlist as $member) {
|
||||||
|
$memberIDs[] = $member['id'];
|
||||||
|
}
|
||||||
|
$data = $database->getVSumField($memberIDs,"pop");
|
||||||
|
|
||||||
|
if (count($data)) {
|
||||||
|
foreach ($data as $row) {
|
||||||
|
$totalpop += $row['Total'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$value['players'] = count($memberlist);
|
$value['players'] = count($memberlist);
|
||||||
$value['totalpop'] = $totalpop;
|
$value['totalpop'] = $totalpop;
|
||||||
if(!isset($value['avg'])) {
|
if(!isset($value['avg'])) {
|
||||||
|
|||||||
@@ -10,8 +10,17 @@ $varmedal = $database->getProfileMedalAlly($aid);
|
|||||||
$allianceinfo = $database->getAlliance($aid);
|
$allianceinfo = $database->getAlliance($aid);
|
||||||
$memberlist = $database->getAllMember($aid);
|
$memberlist = $database->getAllMember($aid);
|
||||||
$totalpop = 0;
|
$totalpop = 0;
|
||||||
|
$memberIDs = [];
|
||||||
|
|
||||||
foreach($memberlist as $member) {
|
foreach($memberlist as $member) {
|
||||||
$totalpop += $database->getVSumField($member['id'],"pop");
|
$memberIDs[] = $member['id'];
|
||||||
|
}
|
||||||
|
$data = $database->getVSumField($memberIDs,"pop");
|
||||||
|
|
||||||
|
if (count($data)) {
|
||||||
|
foreach ($data as $row) {
|
||||||
|
$totalpop += $row['Total'];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
echo "<h1>".$allianceinfo['tag']." - ".$allianceinfo['name']."</h1>";
|
echo "<h1>".$allianceinfo['tag']." - ".$allianceinfo['name']."</h1>";
|
||||||
|
|||||||
@@ -14,9 +14,18 @@ if($allianceinfo['tag']==""){
|
|||||||
header("Location: allianz.php");
|
header("Location: allianz.php");
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
$memberIDs = [];
|
||||||
foreach($memberlist as $member) {
|
foreach($memberlist as $member) {
|
||||||
$totalpop += $database->getVSumField($member['id'],"pop");
|
$memberIDs[] = $member['id'];
|
||||||
}
|
}
|
||||||
|
$data = $database->getVSumField($memberIDs,"pop");
|
||||||
|
|
||||||
|
if (count($data)) {
|
||||||
|
foreach ($data as $row) {
|
||||||
|
$totalpop += $row['Total'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
echo "<h1>".$allianceinfo['tag']." - ".$allianceinfo['name']."</h1>";
|
echo "<h1>".$allianceinfo['tag']." - ".$allianceinfo['name']."</h1>";
|
||||||
|
|
||||||
$profiel="".$allianceinfo['notice']."".md5('skJkev3')."".$allianceinfo['desc']."";
|
$profiel="".$allianceinfo['notice']."".md5('skJkev3')."".$allianceinfo['desc']."";
|
||||||
|
|||||||
Reference in New Issue
Block a user