-
Notifications
You must be signed in to change notification settings - Fork 149
use cache on dynamic group #2058
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -190,27 +190,66 @@ static function getDatas($itemtype, $params, array $forcedisplay=array()) { | |
* | ||
* @since 0.85+1.0 | ||
* | ||
* @param object $group PluginFusioninventoryDeployGroup instance | ||
* @return array | ||
* @param group the group object | ||
* @param use_cache retrieve computers_id from cache (computers_id_cache field) | ||
* @return an array of computer ids | ||
*/ | ||
static function getTargetsByGroup(PluginFusioninventoryDeployGroup $group) { | ||
$search_params = PluginFusioninventoryDeployGroup::getSearchParamsAsAnArray($group, false,true); | ||
if (isset($search_params['metacriteria']) && empty($search_params['metacriteria'])) { | ||
unset($search_params['metacriteria']); | ||
} | ||
$search_params['sort'] = ''; | ||
static function getTargetsByGroup(PluginFusioninventoryDeployGroup $group, $use_cache = false) { | ||
$ids = array(); | ||
|
||
if (!$use_cache || !$ids = self::retrieveCache($group)) { | ||
$search_params = PluginFusioninventoryDeployGroup::getSearchParamsAsAnArray($group, false,true); | ||
if (isset($search_params['metacriteria']) && empty($search_params['metacriteria'])) { | ||
unset($search_params['metacriteria']); | ||
} | ||
|
||
//force no sort (Search engine will sort by id) for better performance | ||
$search_params['sort'] = ''; | ||
|
||
//Only retrieve computers IDs | ||
$results = Search::prepareDatasForSearch('PluginFusioninventoryComputer', $search_params, array('2')); | ||
Search::constructSQL($results); | ||
$results['sql']['search'] = str_replace("`mainitemtype` = 'PluginFusioninventoryComputer'", | ||
//Only retrieve computers IDs | ||
$results = self::getDatas( | ||
'PluginFusioninventoryComputer', | ||
$search_params, | ||
array('2') | ||
); | ||
|
||
$results = Search::prepareDatasForSearch('PluginFusioninventoryComputer', $search_params, array('2')); | ||
Search::constructSQL($results); | ||
$results['sql']['search'] = str_replace("`mainitemtype` = 'PluginFusioninventoryComputer'", | ||
"`mainitemtype` = 'Computer'", $results['sql']['search']); | ||
Search::constructDatas($results); | ||
Search::constructDatas($results); | ||
|
||
$ids = array(); | ||
foreach ($results['data']['rows'] as $row) { | ||
$ids[$row['id']] = $row['id']; | ||
foreach ($results['data']['rows'] as $id => $row) { | ||
$ids[$row['id']] = $row['id']; | ||
} | ||
|
||
//store results in cache (for reusing on agent communication) | ||
self::storeCache($group, $ids); | ||
} | ||
|
||
return $ids; | ||
} | ||
|
||
static function storeCache(PluginFusioninventoryDeployGroup $group, $ids) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add phpdoc |
||
global $DB; | ||
|
||
$query = "UPDATE ".self::getTable()." | ||
SET `computers_id_cache` = '".$DB->escape(json_encode($ids))."' | ||
WHERE `plugin_fusioninventory_deploygroups_id` = '".$group->getID()."'"; | ||
return $DB->query($query); | ||
} | ||
|
||
static function retrieveCache(PluginFusioninventoryDeployGroup $group) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add phpdoc |
||
global $DB; | ||
|
||
$ids = false; | ||
$data = getAllDatasFromTable(self::getTable(), | ||
"`plugin_fusioninventory_deploygroups_id` = '".$group->getID()."'"); | ||
if (count($data)) { | ||
$first = array_shift($data); | ||
$ids = json_decode($first['computers_id_cache'], true); | ||
} | ||
|
||
return $ids; | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -915,6 +915,7 @@ CREATE TABLE `glpi_plugin_fusioninventory_deploygroups_dynamicdatas` ( | |
`plugin_fusioninventory_deploygroups_id` int(11) NOT NULL DEFAULT '0', | ||
`fields_array` text DEFAULT NULL, | ||
`can_update_group` tinyint(1) NOT NULL DEFAULT '0', | ||
`computers_id_cache` text DEFAULT NULL, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On big computers database, perhaps use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, but, should not There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think about that too, but postgresql use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 for longtext |
||
PRIMARY KEY (`id`), | ||
KEY `plugin_fusioninventory_deploygroups_id` (`plugin_fusioninventory_deploygroups_id`), | ||
KEY `can_update_group` (`can_update_group`) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really agree with that, if you call the function with
$use_cache
= 'false' and you have ids in cache, it use cache.So 2 options:
$use_cache
in the functionThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe the notation is a little too compact but here is the different cases:
For resume, as the mentionned 'if' have an OR condition, if the first part is evaluated as true, the second part will not be evaluated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, the second part will not be called if
$use_cache
is set to false.