mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2025-12-07 09:36:05 -08:00
chore: Try to reduce disk IO
This commit is contained in:
@@ -7,8 +7,18 @@
|
|||||||
?>
|
?>
|
||||||
|
|
||||||
<script src="js/graph_online_history.js"></script>
|
<script src="js/graph_online_history.js"></script>
|
||||||
<script>
|
<script >
|
||||||
$.get('/php/server/query_json.php', { file: 'table_online_history.json', nocache: Date.now() }, function(res) {
|
|
||||||
|
|
||||||
|
if (isAppInitialized()) {
|
||||||
|
initOnlineHistoryGraph();
|
||||||
|
} else {
|
||||||
|
callAfterAppInitialized(() => initOnlineHistoryGraph());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function initOnlineHistoryGraph() {
|
||||||
|
$.get('/php/server/query_json.php', { file: 'table_online_history.json', nocache: Date.now() }, function(res) {
|
||||||
// Extracting data from the JSON response
|
// Extracting data from the JSON response
|
||||||
var timeStamps = [];
|
var timeStamps = [];
|
||||||
var onlineCounts = [];
|
var onlineCounts = [];
|
||||||
@@ -39,6 +49,8 @@ $.get('/php/server/query_json.php', { file: 'table_online_history.json', nocache
|
|||||||
// Handle any errors in fetching the data
|
// Handle any errors in fetching the data
|
||||||
console.error('Error fetching online history data.');
|
console.error('Error fetching online history data.');
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
<!-- <canvas id="clientsChart" width="800" height="140" class="extratooltipcanvas no-user-select"></canvas> -->
|
<!-- <canvas id="clientsChart" width="800" height="140" class="extratooltipcanvas no-user-select"></canvas> -->
|
||||||
<canvas id="OnlineChart" style="width:100%; height: 150px; margin-bottom: 15px;"></canvas>
|
<canvas id="OnlineChart" style="width:100%; height: 150px; margin-bottom: 15px;"></canvas>
|
||||||
@@ -9,6 +9,7 @@ from const import (apiPath, sql_appevents, sql_devices_all, sql_events_pending_a
|
|||||||
from logger import mylog
|
from logger import mylog
|
||||||
from helper import write_file, get_setting_value, updateState, timeNowTZ
|
from helper import write_file, get_setting_value, updateState, timeNowTZ
|
||||||
from execution_log import ExecutionLog
|
from execution_log import ExecutionLog
|
||||||
|
from notification import write_notification
|
||||||
|
|
||||||
# Import the start_server function
|
# Import the start_server function
|
||||||
from graphql_server.graphql_server_start import start_server
|
from graphql_server.graphql_server_start import start_server
|
||||||
@@ -127,6 +128,7 @@ class api_endpoint_class:
|
|||||||
# Needs to be called for initial updates
|
# Needs to be called for initial updates
|
||||||
self.try_write()
|
self.try_write()
|
||||||
|
|
||||||
|
#----------------------------------------
|
||||||
def try_write(self):
|
def try_write(self):
|
||||||
current_time = timeNowTZ()
|
current_time = timeNowTZ()
|
||||||
|
|
||||||
@@ -144,7 +146,7 @@ class api_endpoint_class:
|
|||||||
if self.is_ad_hoc_user_event:
|
if self.is_ad_hoc_user_event:
|
||||||
execution_log = ExecutionLog()
|
execution_log = ExecutionLog()
|
||||||
execution_log.finalize_event("update_api")
|
execution_log.finalize_event("update_api")
|
||||||
write_notification(f"[Ad-hoc events] Events executed: update_api", "interrupt", timeNowTZ())
|
self.is_ad_hoc_user_event = False
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Debugging if write is skipped
|
# Debugging if write is skipped
|
||||||
|
|||||||
@@ -861,26 +861,23 @@ def check_and_run_user_event(db, all_plugins, pluginsState):
|
|||||||
event, param = "", ""
|
event, param = "", ""
|
||||||
if len(columns) == 2:
|
if len(columns) == 2:
|
||||||
event, param = columns
|
event, param = columns
|
||||||
|
|
||||||
try:
|
# Process each event type
|
||||||
# Process each event type
|
if event == 'test':
|
||||||
if event == 'test':
|
pluginsState = handle_test(param, db, all_plugins, pluginsState)
|
||||||
pluginsState = handle_test(param, db, all_plugins, pluginsState)
|
executed_events.append(f"test with param {param}")
|
||||||
executed_events.append(f"test with param {param}")
|
execution_log.finalize_event("test")
|
||||||
execution_log.finalize_event("test")
|
elif event == 'run':
|
||||||
elif event == 'run':
|
pluginsState = handle_run(param, db, all_plugins, pluginsState)
|
||||||
pluginsState = handle_run(param, db, all_plugins, pluginsState)
|
executed_events.append(f"run with param {param}")
|
||||||
executed_events.append(f"run with param {param}")
|
execution_log.finalize_event("run")
|
||||||
execution_log.finalize_event("run")
|
elif event == 'update_api':
|
||||||
elif event == 'update_api':
|
# async handling
|
||||||
# async handling
|
update_api(db, all_plugins, False, param.split(','), True)
|
||||||
update_api(db, all_plugins, False, param.split(','), True)
|
|
||||||
|
else:
|
||||||
else:
|
mylog('minimal', ['[check_and_run_user_event] WARNING: Unhandled event in execution queue: ', event, ' | ', param])
|
||||||
mylog('minimal', ['[check_and_run_user_event] WARNING: Unhandled event in execution queue: ', event, ' | ', param])
|
execution_log.finalize_event(event) # Finalize unknown events to remove them
|
||||||
execution_log.finalize_event(event) # Finalize unknown events to remove them
|
|
||||||
except Exception as e:
|
|
||||||
mylog('none', ['[check_and_run_user_event] ERROR: Error processing event "', event, '" with param "', param, '": ', str(e)])
|
|
||||||
|
|
||||||
# Notify user about executed events (if applicable)
|
# Notify user about executed events (if applicable)
|
||||||
if len(executed_events) > 0 and executed_events:
|
if len(executed_events) > 0 and executed_events:
|
||||||
|
|||||||
Reference in New Issue
Block a user