mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2025-12-07 01:26:11 -08:00
optimisations
This commit is contained in:
7
front/php/server/cache-bottom.php
Normal file
7
front/php/server/cache-bottom.php
Normal file
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
// Cache the contents to a cache file
|
||||
$cached = fopen($cachefile, 'w');
|
||||
fwrite($cached, ob_get_contents());
|
||||
fclose($cached);
|
||||
ob_end_flush(); // Send the output to the browser
|
||||
?>
|
||||
15
front/php/server/cache-top.php
Normal file
15
front/php/server/cache-top.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
$url = $_SERVER["SCRIPT_NAME"];
|
||||
$break = Explode('/', $url);
|
||||
$file = $break[count($break) - 1];
|
||||
$cachefile = 'cached-'.substr_replace($file ,"",-4).'.html';
|
||||
$cachetime = 18000;
|
||||
|
||||
// Serve from the cache if it is younger than $cachetime
|
||||
if (file_exists($cachefile) && time() - $cachetime < filemtime($cachefile)) {
|
||||
echo "<!-- Cached copy, generated ".date('H:i', filemtime($cachefile))." -->\n";
|
||||
readfile($cachefile);
|
||||
exit;
|
||||
}
|
||||
ob_start(); // Start the output buffer
|
||||
?>
|
||||
@@ -480,37 +480,20 @@ function PiaToggleArpScan() {
|
||||
function getDevicesTotals() {
|
||||
global $db;
|
||||
|
||||
// All
|
||||
$result = $db->query('SELECT COUNT(*) FROM Devices '. getDeviceCondition ('all'));
|
||||
$row = $result -> fetchArray (SQLITE3_NUM);
|
||||
$devices = $row[0];
|
||||
|
||||
// On-Line
|
||||
$result = $db->query('SELECT COUNT(*) FROM Devices '. getDeviceCondition ('connected') );
|
||||
$row = $result -> fetchArray (SQLITE3_NUM);
|
||||
$connected = $row[0];
|
||||
|
||||
// Favorites
|
||||
$result = $db->query('SELECT COUNT(*) FROM Devices '. getDeviceCondition ('favorites') );
|
||||
$row = $result -> fetchArray (SQLITE3_NUM);
|
||||
$favorites = $row[0];
|
||||
|
||||
// New
|
||||
$result = $db->query('SELECT COUNT(*) FROM Devices '. getDeviceCondition ('new') );
|
||||
$row = $result -> fetchArray (SQLITE3_NUM);
|
||||
$newDevices = $row[0];
|
||||
|
||||
// Down Alerts
|
||||
$result = $db->query('SELECT COUNT(*) FROM Devices '. getDeviceCondition ('down'));
|
||||
$row = $result -> fetchArray (SQLITE3_NUM);
|
||||
$downAlert = $row[0];
|
||||
// combined query
|
||||
$result = $db->query(
|
||||
'SELECT
|
||||
(SELECT COUNT(*) FROM Devices '. getDeviceCondition ('all').') as devices,
|
||||
(SELECT COUNT(*) FROM Devices '. getDeviceCondition ('connected').') as connected,
|
||||
(SELECT COUNT(*) FROM Devices '. getDeviceCondition ('favorites').') as favorites,
|
||||
(SELECT COUNT(*) FROM Devices '. getDeviceCondition ('new').') as new,
|
||||
(SELECT COUNT(*) FROM Devices '. getDeviceCondition ('down').') as down,
|
||||
(SELECT COUNT(*) FROM Devices '. getDeviceCondition ('archived').') as archived
|
||||
');
|
||||
|
||||
// Archived
|
||||
$result = $db->query('SELECT COUNT(*) FROM Devices '. getDeviceCondition ('archived'));
|
||||
$row = $result -> fetchArray (SQLITE3_NUM);
|
||||
$archived = $row[0];
|
||||
$row = $result -> fetchArray (SQLITE3_NUM);
|
||||
|
||||
echo (json_encode (array ($devices, $connected, $favorites, $newDevices, $downAlert, $archived)));
|
||||
echo (json_encode (array ($row[0], $row[1], $row[2], $row[3], $row[4], $row[5])));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -29,4 +29,5 @@ function pia_graph_devices_data($Pia_Graph_Array) {
|
||||
}
|
||||
}
|
||||
$db->close();
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user