Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve performance on updatestore #318

Merged
merged 1 commit into from
Nov 8, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 32 additions & 37 deletions GameEngine/Automation.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ function buildingCP($f,$lvl){
}

public function __construct() {

$this->procNewClimbers();
$this->ClearUser();
$this->ClearInactive();
Expand Down Expand Up @@ -4404,48 +4403,44 @@ private function updateHero() {
// by SlimShady95, aka Manuel Mannhardt < manuel_mannhardt@web.de > UPDATED FROM songeriux < haroldas.snei@gmail.com >
private function updateStore() {
global $bid10, $bid38, $bid11, $bid39;

$result = mysqli_query($GLOBALS['link'],'SELECT * FROM `' . TB_PREFIX . 'fdata`');
while ($row = mysqli_fetch_assoc($result))
{
$dataStore = [];

while ($row = mysqli_fetch_assoc($result)) {
$ress = $crop = 0;
for ($i = 19; $i < 40; ++$i)
{
if ($row['f' . $i . 't'] == 10)
{
$ress += ((isset($bid10[$row['f' . $i]]) && isset($bid10[$row['f' . $i]]['attri'])) ? $bid10[$row['f' . $i]]['attri'] * STORAGE_MULTIPLIER : 0);
}

if ($row['f' . $i . 't'] == 38)
{
$ress += ((isset($bid38[$row['f' . $i]]) && isset($bid38[$row['f' . $i]]['attri'])) ? $bid38[$row['f' . $i]]['attri'] * STORAGE_MULTIPLIER : 0);
}



if ($row['f' . $i . 't'] == 11)
{
$crop += ((isset($bid11[$row['f' . $i]]) && isset($bid11[$row['f' . $i]]['attri'])) ? $bid11[$row['f' . $i]]['attri'] * STORAGE_MULTIPLIER : 0);
}

if ($row['f' . $i . 't'] == 39)
{
$crop += ((isset($bid39[$row['f' . $i]]) && isset($bid39[$row['f' . $i]]['attri'])) ? $bid39[$row['f' . $i]]['attri'] * STORAGE_MULTIPLIER : 0);
for ($i = 19; $i < 40; ++$i) {
$bidVar = 'bid';
switch ($row["f$i". 't']) {
case 10:
case 38:
$bidVar .= $row["f$i". 't'];
if (isset($$bidVar[$row["f$i"]]) && isset($$bidVar[$row["f$i"]]['attri'])) {
$ress += $$bidVar[$row["f$i"]]['attri'] * STORAGE_MULTIPLIER;
}
break;
case 11:
case 39:
$bidVar .= $row["f$i". 't'];
if (isset($$bidVar[$row["f$i"]]) && isset($$bidVar[$row["f$i"]]['attri'])) {
$crop += $$bidVar[$row["f$i"]]['attri'] * STORAGE_MULTIPLIER;
}
break;
}
}

if ($ress == 0)
{
$ress = 800 * STORAGE_MULTIPLIER;
}

if ($crop == 0)
{
$crop = 800 * STORAGE_MULTIPLIER;
}

mysqli_query($GLOBALS['link'],'UPDATE `' . TB_PREFIX . 'vdata` SET `maxstore` = ' . (int) $ress . ', `maxcrop` = ' . (int) $crop . ' WHERE `wref` = ' . (int) $row['vref']) or die(mysqli_error($database->dblink));
$ress = $ress?: 800 * STORAGE_MULTIPLIER;
$crop = $crop?: 800 * STORAGE_MULTIPLIER;
$dataStore[] = [$ress, $crop, $row['vref']];
}

mysqli_begin_transaction($GLOBALS['link']) or die(mysqli_error($database->dblink));;
$sql = 'UPDATE ' .TB_PREFIX. 'vdata SET maxstore = ?, maxcrop = ? WHERE `wref` = ?';
$stmt = mysqli_prepare($GLOBALS['link'], $sql);
foreach ($dataStore as $data) {
$stmt->bind_param('iii', $data[0], $data[1], $data[2]);
$stmt->execute() or die(mysqli_error($database->dblink));
}
mysqli_commit($GLOBALS['link']) or die(mysqli_error($database->dblink));
}

private function oasisResourcesProduce() {
Expand Down