removing DB opens/closes
This commit is contained in:
@@ -8,43 +8,11 @@
|
||||
# Puche 2021 / 2022+ jokob jokob@duck.com GNU GPLv3
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// ## TimeZone processing
|
||||
$configFolderPath = "/home/pi/pialert/config/";
|
||||
$config_file = "pialert.conf";
|
||||
$logFolderPath = "/home/pi/pialert/front/log/";
|
||||
$log_file = "pialert_front.log";
|
||||
|
||||
|
||||
$fullConfPath = $configFolderPath.$config_file;
|
||||
|
||||
$config_file_lines = file($fullConfPath);
|
||||
$config_file_lines_timezone = array_values(preg_grep('/^TIMEZONE\s.*/', $config_file_lines));
|
||||
|
||||
$timeZone = "";
|
||||
|
||||
foreach ($config_file_lines as $line)
|
||||
{
|
||||
if( preg_match('/TIMEZONE(.*?)/', $line, $match) == 1 )
|
||||
{
|
||||
if (preg_match('/\'(.*?)\'/', $line, $match) == 1) {
|
||||
$timeZone = $match[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($timeZone == "")
|
||||
{
|
||||
$timeZone = "Europe/Berlin";
|
||||
}
|
||||
|
||||
date_default_timezone_set($timeZone);
|
||||
|
||||
$date = new DateTime("now", new DateTimeZone($timeZone) );
|
||||
$timestamp = $date->format('Y-m-d_H-i-s');
|
||||
require '/home/pi/pialert/front/php/templates/timezone.php';
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// DB File Path
|
||||
$DBFILE = '../../../db/pialert.db';
|
||||
$DBFILE = '/home/pi/pialert/db/pialert.db';
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Connect DB
|
||||
@@ -101,5 +69,16 @@ function OpenDB (...$DBPath) {
|
||||
|
||||
$db->exec('PRAGMA journal_mode = wal;');
|
||||
}
|
||||
|
||||
function CommitDB () {
|
||||
global $db;
|
||||
|
||||
// $db->commit();
|
||||
}
|
||||
|
||||
// # Open DB once and keep open
|
||||
// # Opening / closing DB frequently actually casues more issues
|
||||
OpenDB (); // main
|
||||
|
||||
|
||||
?>
|
||||
@@ -19,9 +19,6 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// Set maximum execution time to 15 seconds
|
||||
ini_set ('max_execution_time','30');
|
||||
|
||||
// Open DB
|
||||
OpenDB();
|
||||
|
||||
// Action functions
|
||||
if (isset ($_REQUEST['action']) && !empty ($_REQUEST['action'])) {
|
||||
@@ -64,6 +61,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
CommitDB();
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Query Device Data
|
||||
@@ -538,7 +536,7 @@ function ImportCSV() {
|
||||
}
|
||||
|
||||
|
||||
$db->close();
|
||||
CommitDB();
|
||||
|
||||
}
|
||||
|
||||
@@ -939,8 +937,6 @@ function getPholus() {
|
||||
'Extra' => $row['Extra']);
|
||||
}
|
||||
|
||||
$db->close();
|
||||
|
||||
if(count($tableData) == 0)
|
||||
{
|
||||
echo "false";
|
||||
|
||||
@@ -18,9 +18,6 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// Set maximum execution time to 1 minute
|
||||
ini_set ('max_execution_time','60');
|
||||
|
||||
// Open DB
|
||||
OpenDB();
|
||||
|
||||
// Action functions
|
||||
if (isset ($_REQUEST['action']) && !empty ($_REQUEST['action'])) {
|
||||
|
||||
@@ -49,9 +49,6 @@ function getParameter() {
|
||||
// query the database if no cache entry found or requesting live data for the Back_App_State in the header
|
||||
if($parameter == "Back_App_State" || $value == "" )
|
||||
{
|
||||
// Open DB
|
||||
OpenDB();
|
||||
|
||||
global $db;
|
||||
|
||||
$sql = 'SELECT par_Value FROM Parameters
|
||||
@@ -61,8 +58,8 @@ function getParameter() {
|
||||
$row = $result -> fetchArray (SQLITE3_NUM);
|
||||
$value = $row[0];
|
||||
|
||||
// Close DB
|
||||
$db->close();
|
||||
// Commit DB
|
||||
CommitDB();
|
||||
|
||||
// update cookie cache
|
||||
setCache($parameter, $value);
|
||||
@@ -79,9 +76,6 @@ function setParameter() {
|
||||
|
||||
$parameter = $_REQUEST['parameter'];
|
||||
$value = $_REQUEST['value'];
|
||||
|
||||
// Open DB
|
||||
OpenDB();
|
||||
|
||||
global $db;
|
||||
|
||||
@@ -109,8 +103,8 @@ function setParameter() {
|
||||
}
|
||||
}
|
||||
|
||||
// Close DB
|
||||
$db->close();
|
||||
// Commit DB
|
||||
CommitDB();
|
||||
|
||||
// update cookie cache
|
||||
setCache($parameter, $value);
|
||||
|
||||
Reference in New Issue
Block a user