mirror of
https://github.com/Icinga/icingaweb2-module-businessprocess.git
synced 2026-02-02 16:39:25 -05:00
LegacyStorage: Add cache to avoid parsing configurations multiple times
This commit is contained in:
parent
6f3ffe48e2
commit
40538c51ce
7 changed files with 39 additions and 18 deletions
|
|
@ -34,7 +34,7 @@ class ProcessCommand extends Command
|
|||
|
||||
public function init()
|
||||
{
|
||||
$this->storage = new LegacyStorage($this->Config()->getSection('global'));
|
||||
$this->storage = LegacyStorage::getInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -10,9 +10,7 @@ $section = $this->menuSection(N_('Business Processes'), array(
|
|||
));
|
||||
|
||||
try {
|
||||
$storage = new LegacyStorage(
|
||||
$this->getConfig()->getSection('global')
|
||||
);
|
||||
$storage = LegacyStorage::getInstance();
|
||||
|
||||
$prio = 0;
|
||||
foreach ($storage->listProcessNames() as $name) {
|
||||
|
|
|
|||
|
|
@ -631,9 +631,7 @@ class BpConfig
|
|||
protected function storage()
|
||||
{
|
||||
if ($this->storage === null) {
|
||||
$this->storage = new LegacyStorage(
|
||||
Config::module('businessprocess')->getSection('global')
|
||||
);
|
||||
$this->storage = LegacyStorage::getInstance();
|
||||
}
|
||||
|
||||
return $this->storage;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
namespace Icinga\Module\Businessprocess\Director;
|
||||
|
||||
use Icinga\Application\Config;
|
||||
use Icinga\Module\Director\Hook\ShipConfigFilesHook;
|
||||
use Icinga\Module\Businessprocess\Storage\LegacyStorage;
|
||||
|
||||
|
|
@ -12,9 +11,7 @@ class ShipConfigFiles extends ShipConfigFilesHook
|
|||
{
|
||||
$files = array();
|
||||
|
||||
$storage = new LegacyStorage(
|
||||
Config::module('businessprocess')->getSection('global')
|
||||
);
|
||||
$storage = LegacyStorage::getInstance();
|
||||
|
||||
foreach ($storage->listProcesses() as $name => $title) {
|
||||
$files['processes/' . $name . '.bp'] = $storage->getSource($name);
|
||||
|
|
|
|||
|
|
@ -9,6 +9,13 @@ use Icinga\Exception\SystemPermissionException;
|
|||
|
||||
class LegacyStorage extends Storage
|
||||
{
|
||||
/**
|
||||
* All parsed configurations
|
||||
*
|
||||
* @var BpConfig[]
|
||||
*/
|
||||
protected $configs = [];
|
||||
|
||||
/** @var string */
|
||||
protected $configDir;
|
||||
|
||||
|
|
@ -116,10 +123,14 @@ class LegacyStorage extends Storage
|
|||
*/
|
||||
public function loadProcess($name)
|
||||
{
|
||||
return LegacyConfigParser::parseFile(
|
||||
$name,
|
||||
$this->getFilename($name)
|
||||
);
|
||||
if (! isset($this->configs[$name])) {
|
||||
$this->configs[$name] = LegacyConfigParser::parseFile(
|
||||
$name,
|
||||
$this->getFilename($name)
|
||||
);
|
||||
}
|
||||
|
||||
return $this->configs[$name];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -146,6 +157,10 @@ class LegacyStorage extends Storage
|
|||
*/
|
||||
public function loadMetadata($name)
|
||||
{
|
||||
if (isset($this->configs[$name])) {
|
||||
return $this->configs[$name]->getMetadata();
|
||||
}
|
||||
|
||||
return LegacyConfigParser::readMetadataFromFileHeader(
|
||||
$name,
|
||||
$this->getFilename($name)
|
||||
|
|
|
|||
|
|
@ -2,12 +2,18 @@
|
|||
|
||||
namespace Icinga\Module\Businessprocess\Storage;
|
||||
|
||||
use Icinga\Application\Config;
|
||||
use Icinga\Data\ConfigObject;
|
||||
use Icinga\Module\Businessprocess\BpConfig;
|
||||
use Icinga\Module\Businessprocess\Metadata;
|
||||
|
||||
abstract class Storage
|
||||
{
|
||||
/**
|
||||
* @var static
|
||||
*/
|
||||
protected static $instance;
|
||||
|
||||
/**
|
||||
* @var ConfigObject
|
||||
*/
|
||||
|
|
@ -27,6 +33,15 @@ abstract class Storage
|
|||
{
|
||||
}
|
||||
|
||||
public static function getInstance()
|
||||
{
|
||||
if (static::$instance === null) {
|
||||
static::$instance = new static(Config::module('businessprocess')->getSection('global'));
|
||||
}
|
||||
|
||||
return static::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* All processes readable by the current user
|
||||
*
|
||||
|
|
|
|||
|
|
@ -262,9 +262,7 @@ class Controller extends ModuleController
|
|||
protected function storage()
|
||||
{
|
||||
if ($this->storage === null) {
|
||||
$this->storage = new LegacyStorage(
|
||||
$this->Config()->getSection('global')
|
||||
);
|
||||
$this->storage = LegacyStorage::getInstance();
|
||||
}
|
||||
|
||||
return $this->storage;
|
||||
|
|
|
|||
Loading…
Reference in a new issue