Db: caching command/zone name lookup methods

This commit is contained in:
Thomas Gelf 2015-06-08 14:37:02 +02:00
parent 26621f5ab1
commit f848a170d5
1 changed files with 48 additions and 11 deletions

View File

@ -8,6 +8,10 @@ class Db extends DbConnection
{
protected $modules = array();
protected static $zoneCache;
protected static $commandCache;
protected function db()
{
return $this->getDbAdapter();
@ -40,21 +44,42 @@ class Db extends DbConnection
public function enumCommands()
{
if (self::$commandCache === null) {
$select = $this->db()->select()->from('icinga_command', array(
'id',
'object_name',
))
->order('object_name ASC');
return $this->db()->fetchPairs($select);
self::$commandCache = $this->db()->fetchPairs($select);
}
return self::$commandCache;
}
public function enumZones()
{
if (self::$zoneCache === null) {
$select = $this->db()->select()->from('icinga_zone', array(
'id',
'object_name',
))->where('object_type', 'object')->order('object_name ASC');
return $this->db()->fetchPairs($select);
self::$zoneCache = $this->db()->fetchPairs($select);
}
return self::$zoneCache;
}
public function getZoneName($id)
{
$objects = $this->enumZones();
return $objects[$id];
}
public function getCommandName($id)
{
$objects = $this->enumCommands();
return $objects[$id];
}
public function enumHosts()
@ -92,4 +117,16 @@ class Db extends DbConnection
))->where('object_type', 'object')->order('object_name ASC');
return $this->db()->fetchPairs($select);
}
public function clearZoneCache()
{
// TODO: wipe cache on update/insert/delete
self::$zoneCache = null;
}
public function clearCommandCache()
{
// TODO: wipe cache on update/insert/delete
self::$commandCache = null;
}
}