Skip to content

Commit

Permalink
Try using less memory.
Browse files Browse the repository at this point in the history
Use less memory by using method/function calls rather than storing
a lot of data in one variable, then parsing the variable itself.
  • Loading branch information
mastacontrola committed Jan 2, 2017
1 parent 94b1429 commit 99289e3
Show file tree
Hide file tree
Showing 38 changed files with 9,511 additions and 9,580 deletions.
9 changes: 5 additions & 4 deletions packages/web/lib/fog/bootmenu.class.php
Expand Up @@ -427,7 +427,8 @@ private function _ipxeLog()
''
),
);
self::getClass('iPXE', @max(self::getSubObjectIDs('iPXE', $findWhere)))
$id = @max(self::getSubObjectIDs('iPXE', $findWhere));
self::getClass('iPXE', $id)
->set('product', $findWhere['product'])
->set('manufacturer', $findWhere['manufacturer'])
->set('mac', $findWhere['mac'])
Expand Down Expand Up @@ -701,9 +702,9 @@ public function sesscheck()
(array)self::getProgressState()
),
);
$Sessions = self::getClass('MulticastSessionsManager')
->find($findWhere);
foreach ($Sessions as &$MulticastSession) {
foreach ((array)self::getClass('MulticastSessionsManager')
->find($findWhere) as &$MulticastSession
) {
if (!$MulticastSession->isValid()
|| $MulticastSession->get('sessclients') < 1
) {
Expand Down
33 changes: 17 additions & 16 deletions packages/web/lib/fog/fogbase.class.php
Expand Up @@ -505,14 +505,14 @@ public function getAllBlamedNodes()

return $NodeFailure->get('id');
};
$FailedNodes = self::getClass('NodeFailureManager')
->find(
array(
'taskID' => $this->Host->get('task')->get('id'),
'hostID' => $this->Host->get('id'),
)
);
$nodeRet = array_map($nodeFail, (array) $FailedNodes);
$find = array(
'taskID' => $this->Host->get('task')->get('id'),
'hostID' => $this->Host->get('id'),
);
$nodeRet = array_map(
$nodeFail,
(array)self::getClass('NodeFailureManager')->find($find)
);
$nodeRet = array_filter($nodeRet);
$nodeRet = array_unique($nodeRet);
$nodeRet = array_values($nodeRet);
Expand Down Expand Up @@ -793,8 +793,11 @@ protected function arrayRemove($key, array &$array)
*
* @return key or false
*/
protected function arrayFind($needle, array $haystack, $ignorecase = false)
{
protected function arrayFind(
$needle,
array $haystack,
$ignorecase = false
) {
$cmd = $ignorecase !== false ? 'stripos' : 'strpos';
foreach ($haystack as $key => &$value) {
if (false !== $cmd($value, $needle)) {
Expand Down Expand Up @@ -2178,13 +2181,11 @@ public function wakeUp($macs)
if ($macCount < 1) {
return;
}
$Nodes = self::getClass('StorageNodeManager')
foreach ((array)self::getClass('StorageNodeManager')
->find(
array(
'isEnabled' => 1,
)
);
foreach ((array) $Nodes as &$Node) {
array('isEnabled' => 1)
) as &$Node
) {
$ip = $Node->get('ip');
$nodeURLs[] = sprintf(
$url,
Expand Down
23 changes: 12 additions & 11 deletions packages/web/lib/fog/fogmanagercontroller.class.php
Expand Up @@ -852,7 +852,7 @@ public function destroy(
);
$destroyVals = array();
$ids = array_chunk($ids, 500);
foreach ((array) $ids as &$id) {
foreach ((array)$ids as &$id) {
foreach ((array) $id as $index => &$id_1) {
$keyStr = sprintf('id_%d', $index);
$destroyKeys[] = sprintf(':%s', $keyStr);
Expand Down Expand Up @@ -907,17 +907,18 @@ public function buildSelectBox(
$elementName = strtolower($this->childClass);
}
$this->orderBy($orderBy);
$items = $this->find(
$filter ? array('id' => $filter) : '',
'',
$orderBy,
'',
'',
'',
($filter ? true : false)
);
ob_start();
foreach ((array) $items as &$Object) {
foreach ((array)$this
->find(
$filter ? array('id' => $filter) : '',
'',
$orderBy,
'',
'',
'',
($filter ? true : false)
) as &$Object
) {
if (!$Object->isValid()) {
continue;
}
Expand Down
76 changes: 33 additions & 43 deletions packages/web/lib/fog/fogpage.class.php
Expand Up @@ -480,7 +480,7 @@ public function index()
);
if ($sub != 'list') {
if ($_SESSION['DataReturn'] > 0) {
$objCount = $this->getClass($manager)->count();
$objCount = self::getClass($manager)->count();
if ($objCount > $_SESSION['DataReturn']) {
$this->redirect(
sprintf(
Expand All @@ -498,9 +498,7 @@ public function index()
'pending' => array(0, '')
);
}
$Items = self::getClass($manager)->find($find);
array_walk($Items, static::$returnData);
unset($Items);
array_walk(self::getClass($manager)->find($find), static::$returnData);
$event = sprintf(
'%s_DATA',
strtoupper($this->node)
Expand Down Expand Up @@ -1075,14 +1073,11 @@ public function deploy()
);
if ($this->obj instanceof Host) {
ob_start();
$Snapins = self::getClass('SnapinManager')
foreach ((array)self::getClass('SnapinManager')
->find(
array('id' => $this->obj->get('snapins'))
);
foreach ((array)$Snapins as &$Snapin) {
if (!$Snapin->isValid()) {
continue;
}
) as &$Snapin
) {
printf(
'<option value="%d">%s - (%d)</option>',
$Snapin->get('id'),
Expand Down Expand Up @@ -1258,14 +1253,11 @@ public function deploy()
);
}
if ($this->obj instanceof Group) {
$hostIDs = $this->obj->get('hosts');
$Hosts = self::getClass('HostManager')
->find(array('id' => $hostIDs));
unset($hostIDs);
foreach ((array)$Hosts as $index => &$Host) {
if (!$Host->isValid()) {
continue;
}
foreach ((array)self::getClass('HostManager')
->find(
array('id' => $this->obj->get('hosts'))
) as &$Host
) {
$imageID = $imageName = '';
if ($TaskType->isImagingTask()) {
$Image = $Host->getImage();
Expand Down Expand Up @@ -1721,12 +1713,12 @@ public function deletemulti()
$reqID = explode(',', $_REQUEST[$reqID]);
$reqID = array_unique($reqID);
$reqID = array_filter($reqID);
$Objects = self::getClass($this->childClass)
foreach ((array)self::getClass($this->childClass)
->getManager()
->find(
array('id' => $reqID)
);
foreach ((array)$Objects as &$Object) {
) as &$Object
) {
if ($Object->get('protected')) {
continue;
}
Expand Down Expand Up @@ -1869,16 +1861,17 @@ public function basictasksOptions()
);
unset($TaskType);
};
$TaskTypes = self::getClass('TaskTypeManager')
$find = array(
'access' => array('both', $this->node),
'isAdvanced' => 0
);
foreach ((array)self::getClass('TaskTypeManager')
->find(
array(
'access' => array('both', $this->node),
'isAdvanced' => 0
),
$find,
'AND',
'id'
);
foreach ((array)$TaskTypes as &$TaskType) {
) as &$TaskType
) {
$taskTypeIterator($TaskType);
unset($TaskType);
}
Expand Down Expand Up @@ -1920,16 +1913,17 @@ public function basictasksOptions()
_('Advanced Actions')
);
unset($TaskTypes);
$TaskTypes = self::getClass('TaskTypeManager')
$find = array(
'access' => array('both', $this->node),
'isAdvanced' => 1
);
foreach ((array)self::getClass('TaskTypeManager')
->find(
array(
'access' => array('both', $this->node),
'isAdvanced' => 1
),
$find,
'AND',
'id'
);
foreach ((array)$TaskTypes as &$TaskType) {
) as &$TaskType
) {
$taskTypeIterator($TaskType);
unset($TaskType);
}
Expand Down Expand Up @@ -3000,8 +2994,7 @@ public function searchPost()
'%sManager',
$this->childClass
);
$items = self::getClass($manager)->search('', true);
array_walk($items, static::$returnData);
array_walk(self::getClass($manager)->search('', true), static::$returnData);
$event = sprintf(
'%s_DATA',
strtoupper($this->node)
Expand Down Expand Up @@ -3317,13 +3310,10 @@ public function export()
);
$report = self::getClass('ReportMaker');
$this->arrayRemove('id', $this->databaseFields);
$objects = self::getClass($this->childClass)
foreach ((array)self::getClass($this->childClass)
->getManager()
->find();
foreach ((array)$objects as $index => &$Item) {
if (!$Item->isValid()) {
continue;
}
->find() as &$Item
) {
if ($Item instanceof Host) {
$macs = $maccolumn = array();
$macs[] = $Item->get('mac');
Expand Down
9 changes: 3 additions & 6 deletions packages/web/lib/fog/image.class.php
Expand Up @@ -201,17 +201,14 @@ public function deleteFile()
if ($this->get('protected')) {
throw new Exception(self::$foglang['ProtectedImage']);
}
$StorageNodes = self::getClass('StorageNodeManager')
foreach ((array)self::getClass('StorageNodeManager')
->find(
array(
'storagegroupID' => $this->get('storagegroups'),
'isEnabled' => 1
)
);
foreach ((array)$StorageNodes as &$StorageNode) {
if (!$StorageNode->isValid()) {
continue;
}
) as &$StorageNode
) {
$ftppath = $StorageNode->get('ftppath');
$ftppath = trim($ftppath, '/');
$deleteFile = sprintf(
Expand Down
11 changes: 4 additions & 7 deletions packages/web/lib/fog/snapin.class.php
Expand Up @@ -163,17 +163,14 @@ public function deleteFile()
if ($this->get('protected')) {
throw new Exception(self::$foglang['ProtectedSnapin']);
}
$StorageNodes = self::getClass('StorageNodeManager')
foreach ((array)self::getClass('StorageNodeManager')
->find(
array(
'storagegroupID' => $this->get('storagegroups'),
'isEnabled' => 1,
'isEnabled' => 1
)
);
foreach ((array) $StorageNodes as &$StorageNode) {
if (!$StorageNode->isValid()) {
continue;
}
) as &$StorageNode
) {
$ftppath = $StorageNode->get('snapinpath');
$ftppath = trim($ftppath, '/');
$deleteFile = sprintf(
Expand Down
13 changes: 7 additions & 6 deletions packages/web/lib/fog/storagegroup.class.php
Expand Up @@ -125,10 +125,11 @@ protected function loadEnablednodes()
'maxClients' => range(1, 9999),
'isEnabled' => 1
);
$nodes = $this->getClass('StorageNodeManager')->find($find);
$nodeids = array();
$testurls = array();
foreach ($nodes as &$node) {
foreach ((array)self::getClass('StorageNodeManager')
->find($find) as &$node
) {
$testurls[] = sprintf(
'http://%s/fog/management/index.php',
$node->get('ip')
Expand Down Expand Up @@ -270,12 +271,12 @@ public function getOptimalStorageNode()
if (count($this->get('enablednodes')) < 1) {
$getter = 'allnodes';
}
$Nodes = self::getClass('StorageNodeManager')
$winner = null;
foreach ((array)self::getClass('StorageNodeManager')
->find(
array('id' => $this->get($getter))
);
$winner = null;
foreach ((array)$Nodes as &$Node) {
) as &$Node
) {
if ($winner == null
|| $Node->getClientLoad() < $winner->getClientLoad()
) {
Expand Down
6 changes: 3 additions & 3 deletions packages/web/lib/fog/storagenode.class.php
Expand Up @@ -141,14 +141,14 @@ public function getStorageGroup()
*/
public function getNodeFailure($Host)
{
$Fails = self::getClass('NodeFailureManager')
foreach ((array)self::getClass('NodeFailureManager')
->find(
array(
'storagenodeID' => $this->get('id'),
'hostID' => $Host,
)
);
foreach ((array) $Fails as &$Failed) {
) as &$Failed
) {
$curr = self::niceDate();
$prev = $Failed->get('failureTime');
$prev = self::niceDate($prev);
Expand Down
2 changes: 1 addition & 1 deletion packages/web/lib/fog/system.class.php
Expand Up @@ -53,7 +53,7 @@ private static function _versionCompare()
public function __construct()
{
self::_versionCompare();
define('FOG_VERSION', '40480');
define('FOG_VERSION', '941451');
define('FOG_SCHEMA', 244);
define('FOG_BCACHE_VER', 111);
define('FOG_SVN_REVISION', 6052);
Expand Down

0 comments on commit 99289e3

Please sign in to comment.