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() {
|
function getDevicesTotals() {
|
||||||
global $db;
|
global $db;
|
||||||
|
|
||||||
// All
|
// combined query
|
||||||
$result = $db->query('SELECT COUNT(*) FROM Devices '. getDeviceCondition ('all'));
|
$result = $db->query(
|
||||||
$row = $result -> fetchArray (SQLITE3_NUM);
|
'SELECT
|
||||||
$devices = $row[0];
|
(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
|
||||||
|
');
|
||||||
|
|
||||||
// On-Line
|
|
||||||
$result = $db->query('SELECT COUNT(*) FROM Devices '. getDeviceCondition ('connected') );
|
|
||||||
$row = $result -> fetchArray (SQLITE3_NUM);
|
$row = $result -> fetchArray (SQLITE3_NUM);
|
||||||
$connected = $row[0];
|
|
||||||
|
|
||||||
// Favorites
|
echo (json_encode (array ($row[0], $row[1], $row[2], $row[3], $row[4], $row[5])));
|
||||||
$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];
|
|
||||||
|
|
||||||
// Archived
|
|
||||||
$result = $db->query('SELECT COUNT(*) FROM Devices '. getDeviceCondition ('archived'));
|
|
||||||
$row = $result -> fetchArray (SQLITE3_NUM);
|
|
||||||
$archived = $row[0];
|
|
||||||
|
|
||||||
echo (json_encode (array ($devices, $connected, $favorites, $newDevices, $downAlert, $archived)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -29,4 +29,5 @@ function pia_graph_devices_data($Pia_Graph_Array) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
$db->close();
|
$db->close();
|
||||||
|
|
||||||
?>
|
?>
|
||||||
Reference in New Issue
Block a user