Improve performance of billing poller

This commit is contained in:
Richard
2016-03-01 10:20:25 +00:00
parent 282ac48dfd
commit d759c4ac9d
2 changed files with 7 additions and 8 deletions

View File

@ -82,10 +82,8 @@ function getValue($host, $port, $id, $inout) {
function getLastPortCounter($port_id, $inout) {
$return = array();
$rows = dbFetchCell('SELECT count(counter) from `port_'.mres($inout)."_measurements` WHERE `port_id`='".mres($port_id)."'");
if ($rows > 0) {
$row = dbFetchRow('SELECT counter,delta FROM `port_'.mres($inout)."_measurements` WHERE `port_id`='".mres($port_id)."' ORDER BY timestamp DESC");
$row = dbFetchRow('SELECT counter,delta FROM `port_'.mres($inout)."_measurements` WHERE `port_id`='".mres($port_id)."' ORDER BY timestamp DESC LIMIT 1");
if (!is_null($row)) {
$return[counter] = $row['counter'];
$return[delta] = $row['delta'];
$return[state] = 'ok';
@ -101,10 +99,8 @@ function getLastPortCounter($port_id, $inout) {
function getLastMeasurement($bill_id) {
$return = array();
$rows = dbFetchCell("SELECT count(delta) from bill_data WHERE bill_id='".mres($bill_id)."'");
if ($rows > 0) {
$row = dbFetchRow("SELECT timestamp,delta,in_delta,out_delta FROM bill_data WHERE bill_id='".mres($bill_id)."' ORDER BY timestamp DESC");
$row = dbFetchRow("SELECT timestamp,delta,in_delta,out_delta FROM bill_data WHERE bill_id='".mres($bill_id)."' ORDER BY timestamp DESC LIMIT 1");
if (!is_null($row)) {
$return[delta] = $row['delta'];
$return[delta_in] = $row['delta_in'];
$return[delta_out] = $row['delta_out'];

3
sql-schema/106.sql Normal file
View File

@ -0,0 +1,3 @@
ALTER TABLE port_in_measurements ADD INDEX (`port_id`, `timestamp`);
ALTER TABLE port_out_measurements ADD INDEX (`port_id`, `timestamp`);
ALTER TABLE bill_data ADD INDEX (`bill_id`, `timestamp`);