improve efficiency of devices/ports/, add some caching, fix db profiling.

git-svn-id: http://www.observium.org/svn/observer/trunk@2349 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
Adam Amstrong
2011-05-19 10:02:55 +00:00
parent 2978386af4
commit bf1d43ae65
6 changed files with 67 additions and 16 deletions
+36 -5
View File
@@ -48,6 +48,42 @@ function get_sensor_rrd($device, $sensor)
return($rrd_file);
}
function get_port_by_index_cache($device_id, $ifIndex)
{
global $port_index_cache;
if (isset($port_index_cache[$device_id][$ifIndex]) && is_array($port_index_cache[$device_id][$ifIndex]))
{
$port = $port_index_cache[$device_id][$ifIndex];
} else {
$port = get_port_by_ifIndex($device_id, $ifIndex);
$port_index_cache[$device_id][$ifIndex] = $port;
}
return $port;
}
function get_port_by_ifIndex($device_id, $ifIndex)
{
return dbFetchRow("SELECT * FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ?", array($device_id, $ifIndex));
}
function port_by_id_cache($port_id)
{
global $port_cache;
if (isset($port_cache[$port_id]) && is_array($port_cache[$device_id]))
{
$port = $port_cache[$port_id];
} else {
$port = dbFetchRow("SELECT * FROM `ports` WHERE `interface_id` = ?", array($port_id));
$port_cache[$port_id] = $port;
}
return $port;
}
function get_port_by_id($port_id)
{
if (is_numeric($port_id))
@@ -184,11 +220,6 @@ function getifindexbyid($id)
return dbFetchCell("SELECT `ifIndex` FROM `ports` WHERE `interface_id` = ?", array($id));
}
function get_port_by_ifIndex($device, $ifIndex)
{
return dbFetchRow("SELECT * FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ?", array($device['device_id'], $ifIndex));
}
function getifbyid($id)
{
return dbFetchRow("SELECT * FROM `ports` WHERE `interface_id` = ?", array($id));