Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve performance of billing poller #3129

Merged
merged 1 commit into from Mar 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 4 additions & 8 deletions includes/billing.php
Expand Up @@ -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';
Expand All @@ -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'];
Expand Down
3 changes: 3 additions & 0 deletions sql-schema/106.sql
@@ -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`);