Skip to content

Commit

Permalink
Change to how we build set of ids for joined data. Added getMemoryLim…
Browse files Browse the repository at this point in the history
…it() helper (account for new G setting for memory_limit)
  • Loading branch information
cheesegrits committed Jan 7, 2018
1 parent ac442e9 commit 0957b7e
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 12 deletions.
19 changes: 18 additions & 1 deletion components/com_fabrik/models/list.php
Original file line number Diff line number Diff line change
Expand Up @@ -2593,6 +2593,7 @@ public function buildQuery()
* $$$ rob get an array containing the PRIMARY key values for each joined tables data.
* Stop as soon as we have a set of ids totaling the sum of records contained in $idRows
*/
/*
while (count($ids) < $maxPossibleIds && $lookupC >= 0)
{
$ids = ArrayHelper::getColumn($idRows, '__pk_val' . $lookupC);
Expand All @@ -2614,6 +2615,13 @@ public function buildQuery()
$lookupC--;
}
}
*/


foreach ($lookUpNames as $c => $lookUpName)
{
$ids[$lookUpName] = ArrayHelper::getColumn($idRows, '__pk_val' . $c);
}
}

// Now lets actually construct the query that will get the required records:
Expand All @@ -2634,10 +2642,19 @@ public function buildQuery()
*/
if (!empty($ids))
{
/*
if ($lookUpNames[$lookupC] !== $table->db_primary_key)
{
$query->where($lookUpNames[$lookupC] . ' IN (' . implode(array_unique($ids), ',') . ')');
}
*/
foreach ($ids as $lookUpName => $pks)
{
if ($lookUpName !== $table->db_primary_key)
{
$query->where($lookUpName . ' IN (' . implode(array_unique($pks), ',') . ')');
}
}

if (!empty($mainKeys))
{
Expand Down Expand Up @@ -9526,7 +9543,7 @@ public function getInsertRowsSQL($oExporter)
{
@set_time_limit(300);
$table = $this->getTable();
$memoryLimit = ini_get('memory_limit');
$memoryLimit = FabrikWorker::getMemoryLimit();
$db = $this->getDb();
/*
* don't load in all the table data as on large tables this gives a memory error
Expand Down
11 changes: 8 additions & 3 deletions libraries/fabrik/fabrik/Helpers/Image/Imagegd.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ public function imageFromFile($file)
}

ini_set('display_errors', true);
$memory = ini_get('memory_limit');
$intMemory = StringHelper::rtrimword($memory, 'M');
$memory = \FabrikWorker::getMemoryLimit(true);
$intMemory = \FabrikWorker::getMemoryLimit();

if ($intMemory < 50)
if ($intMemory < (64 * 1024 * 1024))
{
ini_set('memory_limit', '50M');
}
Expand Down Expand Up @@ -81,6 +81,11 @@ public function imageFromFile($file)
}
}

if ($intMemory < (64 * 1024 * 1024))
{
ini_set('memory_limit', $memory);
}

return array($img, $header);
}

Expand Down
12 changes: 8 additions & 4 deletions libraries/fabrik/fabrik/Helpers/Image/Imagegd2.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ public function resize($maxWidth, $maxHeight, $origFile, $destFile, $quality = 1
}

ini_set('display_errors', true);
$memory = ini_get('memory_limit');
$intMemory = StringHelper::rtrimword($memory, 'M');
$memory = \FabrikWorker::getMemoryLimit(true);
$intMemory = \FabrikWorker::getMemoryLimit();

if ($intMemory < 50)
if ($intMemory < (64 * 1024 * 1024))
{
ini_set('memory_limit', '50M');
}
Expand Down Expand Up @@ -167,7 +167,11 @@ public function resize($maxWidth, $maxHeight, $origFile, $destFile, $quality = 1
}

$this->thumbPath = $destFile;
ini_set('memory_limit', $memory);

if ($intMemory < (64 * 1024 * 1024))
{
ini_set('memory_limit', $memory);
}
}
}

25 changes: 25 additions & 0 deletions libraries/fabrik/fabrik/Helpers/Worker.php
Original file line number Diff line number Diff line change
Expand Up @@ -2731,4 +2731,29 @@ public static function getID3Instance()

return $getID3;
}

public static function getMemoryLimit($symbolic = false)
{
$memory = trim(ini_get('memory_limit'));
$memory = trim($memory);

if ($symbolic)
{
return $memory;
}

$last = strtolower($memory[strlen($memory)-1]);
$val = substr($memory, 0, -1);

switch($last) {
case 'g':
$val *= 1024;
case 'm':
$val *= 1024;
case 'k':
$val *= 1024;
}

return $val;
}
}
28 changes: 24 additions & 4 deletions plugins/system/fabrik/fabrik.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public static function clearJs()

/**
* Store head script in session js store,
* used by partial document type to exclude scripts already loaded
* used by partial document type to exclude scripts already loaded, when building modal windows
*
* @return void
*/
Expand All @@ -157,7 +157,28 @@ public static function storeHeadJs()
if (!empty($key))
{
$key = 'fabrik.js.head.cache.' . $key;
$scripts = json_encode($doc->_scripts);

// if this is 'html', it's a main page load, so clear the cache for this page and start again
if ($app->input->get('format', 'html') === 'html')
{
$session->clear($key);
}

$scripts = $doc->_scripts;
$existing = $session->get($key);

/**
* if we already have scripts for this page, merge the new ones. For example, this might be an AJAX
* call loading an element, so we just want to add any new scripts to the list, not blow it away and replace
*/
if (!empty($existing))
{
$existing = json_decode($existing);
$existing = ArrayHelper::fromObject($existing);
$scripts = array_merge($scripts, $existing);
}

$scripts = json_encode($scripts);
$session->set($key, $scripts);
}
}
Expand Down Expand Up @@ -400,8 +421,7 @@ public static function onDoContentSearch($text, $params, $phrase = '', $ordering
$input->set('resetfilters', 1);

// Ensure search doesn't go over memory limits
$memory = ini_get('memory_limit');
$memory = (int) FabrikString::rtrimword($memory, 'M') * 1000000;
$memory = FabrikWorker::getMemoryLimit();
$usage = array();
$memSafety = 0;

Expand Down

0 comments on commit 0957b7e

Please sign in to comment.