diff options
author | Simon Rettberg | 2021-05-06 10:26:09 +0200 |
---|---|---|
committer | Simon Rettberg | 2021-05-11 14:51:13 +0200 |
commit | 8dc2b92d667f1401ab9f1315a36add61658f899c (patch) | |
tree | 452c5fe040055884cf9d9ee834415db84999a9a1 /modules-available/statistics/pages/summary.inc.php | |
parent | [session] Add simple session overview table (diff) | |
download | slx-admin-8dc2b92d667f1401ab9f1315a36add61658f899c.tar.gz slx-admin-8dc2b92d667f1401ab9f1315a36add61658f899c.tar.xz slx-admin-8dc2b92d667f1401ab9f1315a36add61658f899c.zip |
Moderize Database handling
* Auto-convert to utf8mb4_unicode_520_ci
* Use foreach instead of while to loop over results
* Drop useless statement caching
* Keep emulated prepares, as we sometimes loop over nested queries
Diffstat (limited to 'modules-available/statistics/pages/summary.inc.php')
-rw-r--r-- | modules-available/statistics/pages/summary.inc.php | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/modules-available/statistics/pages/summary.inc.php b/modules-available/statistics/pages/summary.inc.php index ce67070e..4599b8b6 100644 --- a/modules-available/statistics/pages/summary.inc.php +++ b/modules-available/statistics/pages/summary.inc.php @@ -67,7 +67,7 @@ class SubPage $points1 = array('data' => array(), 'label' => 'Online', 'fillColor' => '#efe', 'strokeColor' => '#aea', 'pointColor' => '#7e7', 'pointStrokeColor' => '#fff', 'pointHighlightFill' => '#fff', 'pointHighlightStroke' => '#7e7'); $points2 = array('data' => array(), 'label' => 'In use', 'fillColor' => '#fee', 'strokeColor' => '#eaa', 'pointColor' => '#e77', 'pointStrokeColor' => '#fff', 'pointHighlightFill' => '#fff', 'pointHighlightStroke' => '#e77'); $sum = 0; - while ($row = $res->fetch(PDO::FETCH_ASSOC)) { + foreach ($res as $row) { $x = explode('#', $row['data']); if ($sum === 0) { $labels[] = date('H:i', $row['dateline']); @@ -103,7 +103,7 @@ class SubPage $lines = array(); $json = array(); $id = 0; - while ($row = $res->fetch(PDO::FETCH_ASSOC)) { + foreach ($res as $row) { if (empty($row['systemmodel'])) { continue; } @@ -131,7 +131,7 @@ class SubPage $res = Database::simpleQuery("SELECT mbram, Count(*) AS `count` FROM machine m $join WHERE $where GROUP BY mbram", $args); $lines = array(); - while ($row = $res->fetch(PDO::FETCH_ASSOC)) { + foreach ($res as $row) { $gb = (int)ceil($row['mbram'] / 1024); for ($i = 1; $i < count(StatisticsFilter::SIZE_RAM); ++$i) { if (StatisticsFilter::SIZE_RAM[$i] < $gb) { @@ -178,7 +178,7 @@ class SubPage WHERE $where GROUP BY kvmstate ORDER BY `count` DESC", $args); $lines = array(); $json = array(); - while ($row = $res->fetch(PDO::FETCH_ASSOC)) { + foreach ($res as $row) { $lines[] = $row; $json[] = array( 'color' => isset($colors[$row['kvmstate']]) ? $colors[$row['kvmstate']] : '#000', @@ -198,7 +198,7 @@ class SubPage $res = Database::simpleQuery("SELECT id44mb, Count(*) AS `count` FROM machine m $join WHERE $where GROUP BY id44mb", $args); $lines = array(); $total = 0; - while ($row = $res->fetch(PDO::FETCH_ASSOC)) { + foreach ($res as $row) { $total += $row['count']; $gb = (int)ceil($row['id44mb'] / 1024); for ($i = 1; $i < count(StatisticsFilter::SIZE_ID44); ++$i) { @@ -251,7 +251,7 @@ class SubPage . " WHERE firstseen > :cutoff AND $where ORDER BY firstseen DESC LIMIT 32", $args); $rows = array(); $count = 0; - while ($row = $res->fetch(PDO::FETCH_ASSOC)) { + foreach ($res as $row) { if (empty($row['hostname'])) { $row['hostname'] = $row['clientip']; } |