From 83d7bbdd1bf561d4edfe8b575215ac96468cf200 Mon Sep 17 00:00:00 2001 From: Tony Murray Date: Thu, 15 Sep 2016 02:45:45 -0500 Subject: [PATCH] fix: reduce mib graph queries (#4439) Used have 1 query for every graph type known to LibreNMS. Now it just gets a list of the graphs for the device and checks against that. --- includes/common.php | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/includes/common.php b/includes/common.php index 5e6b61faf6..abf242305e 100644 --- a/includes/common.php +++ b/includes/common.php @@ -739,11 +739,15 @@ function get_graph_subtypes($type, $device = null) closedir($handle); } - // find the MIB subtypes - foreach ($config['graph_types'] as $type => $unused1) { - foreach ($config['graph_types'][$type] as $subtype => $unused2) { - if (is_mib_graph($type, $subtype) && $device != null && is_device_graph($device, $subtype)) { - $types[] = $subtype; + if ($device != null) { + // find the MIB subtypes + $graphs = get_device_graphs($device); + + foreach ($config['graph_types'] as $type => $unused1) { + foreach ($config['graph_types'][$type] as $subtype => $unused2) { + if (is_mib_graph($type, $subtype) && in_array($graphs, $subtype)) { + $types[] = $subtype; + } } } } @@ -752,13 +756,11 @@ function get_graph_subtypes($type, $device = null) return $types; } // get_graph_subtypes - -function is_device_graph($device, $subtype) +function get_device_graphs($device) { - $query = 'SELECT COUNT(*) FROM `device_graphs` WHERE `device_id` = ? AND `graph` = ?'; - return dbFetchCell($query, array($device['device_id'], $subtype)) > 0; -} // is_device_graph - + $query = 'SELECT `graph` FROM `device_graphs` WHERE `device_id` = ?'; + return dbFetchColumn($query, array($device['device_id'])); +} function get_smokeping_files($device) {