This repository has been archived by the owner on Apr 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 149
use cache on dynamic group #2058
Merged
orthagh
merged 3 commits into
fusioninventory:glpi9.1
from
orthagh:cache_dynamic_groups
May 10, 2017
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.