chore: Try to reduce disk IO

This commit is contained in:
jokob-sk
2024-12-17 07:04:00 +11:00
parent c132374421
commit caf5a5347c
3 changed files with 34 additions and 23 deletions

View File

@@ -7,8 +7,18 @@
?>
<script src="js/graph_online_history.js"></script>
<script>
$.get('/php/server/query_json.php', { file: 'table_online_history.json', nocache: Date.now() }, function(res) {
<script >
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
var timeStamps = [];
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
console.error('Error fetching online history data.');
});
}
</script>
<!-- <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>

View File

@@ -9,6 +9,7 @@ from const import (apiPath, sql_appevents, sql_devices_all, sql_events_pending_a
from logger import mylog
from helper import write_file, get_setting_value, updateState, timeNowTZ
from execution_log import ExecutionLog
from notification import write_notification
# Import the start_server function
from graphql_server.graphql_server_start import start_server
@@ -127,6 +128,7 @@ class api_endpoint_class:
# Needs to be called for initial updates
self.try_write()
#----------------------------------------
def try_write(self):
current_time = timeNowTZ()
@@ -144,7 +146,7 @@ class api_endpoint_class:
if self.is_ad_hoc_user_event:
execution_log = ExecutionLog()
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:
# Debugging if write is skipped

View File

@@ -861,26 +861,23 @@ def check_and_run_user_event(db, all_plugins, pluginsState):
event, param = "", ""
if len(columns) == 2:
event, param = columns
try:
# Process each event type
if event == 'test':
pluginsState = handle_test(param, db, all_plugins, pluginsState)
executed_events.append(f"test with param {param}")
execution_log.finalize_event("test")
elif event == 'run':
pluginsState = handle_run(param, db, all_plugins, pluginsState)
executed_events.append(f"run with param {param}")
execution_log.finalize_event("run")
elif event == 'update_api':
# async handling
update_api(db, all_plugins, False, param.split(','), True)
else:
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
except Exception as e:
mylog('none', ['[check_and_run_user_event] ERROR: Error processing event "', event, '" with param "', param, '": ', str(e)])
# Process each event type
if event == 'test':
pluginsState = handle_test(param, db, all_plugins, pluginsState)
executed_events.append(f"test with param {param}")
execution_log.finalize_event("test")
elif event == 'run':
pluginsState = handle_run(param, db, all_plugins, pluginsState)
executed_events.append(f"run with param {param}")
execution_log.finalize_event("run")
elif event == 'update_api':
# async handling
update_api(db, all_plugins, False, param.split(','), True)
else:
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
# Notify user about executed events (if applicable)
if len(executed_events) > 0 and executed_events: