diff --git a/front/js/graph_resource_history.js b/front/js/graph_resource_history.js index f5cbe17c3..56be2226d 100644 --- a/front/js/graph_resource_history.js +++ b/front/js/graph_resource_history.js @@ -2,6 +2,12 @@ // building a new one on the same canvas (Chart.js throws otherwise). var resourceHistoryChartInstances = {}; +// Monotonically increasing id, bumped on every initResourceHistoryGraphs() +// call. A fast double-click across two range buttons fires two overlapping +// AJAX requests; without this, whichever response lands last wins regardless +// of click order, so a stale response can silently overwrite newer data. +var resourceHistoryRequestId = 0; + // Chart axis labels: time only - date/year are dropped entirely to keep the // axis readable; the full date (including year) is still available on // hover via each chart's tooltip title callback below. Passed as @@ -25,7 +31,13 @@ var CHART_TIMESTAMP_OPTIONS_TOOLTIP = { * message when no rows exist yet (collection off, or just enabled). */ function initResourceHistoryGraphs(range) { + var requestId = ++resourceHistoryRequestId; + $.get('php/server/query_json.php', { file: `table_resource_history_${range}.json`, nocache: Date.now() }, function (res) { + if (requestId !== resourceHistoryRequestId) { + return; // a newer range request has since started - discard this stale response + } + var rows = (res && res.data) ? res.data : []; if (rows.length === 0) { diff --git a/front/systeminfoStorage.php b/front/systeminfoStorage.php index 99eb47202..f01e2d5aa 100755 --- a/front/systeminfoStorage.php +++ b/front/systeminfoStorage.php @@ -21,16 +21,25 @@ $nax_db_size = file_exists($nax_db) ? number_format((filesize($nax_db) / 1000000 $nax_wal_size = file_exists($nax_wal) ? number_format((filesize($nax_wal) / 1000000), 2, ",", ".") . ' MB' : '0 MB'; $nax_db_mod = file_exists($nax_db) ? date("F d Y H:i:s", filemtime($nax_db)) : 'N/A'; -// Table row counts +// Table row counts. Read-only + existence check: a plain `new SQLite3($nax_db)` +// with default flags would CREATE an empty app.db if the path is ever wrong/ +// missing (e.g. before first scan), and an unhandled open/query exception here +// would previously fatal-error this entire AJAX-loaded tab, not just this box. $tableSizesHTML = ""; -$db_info_conn = new SQLite3($nax_db); -$table_names_result = $db_info_conn->query("SELECT name FROM sqlite_master WHERE type='table'"); -while ($row = $table_names_result->fetchArray(SQLITE3_ASSOC)) { - $tableName = $row['name']; - $countResult = $db_info_conn->querySingle("SELECT COUNT(*) FROM $tableName"); - $tableSizesHTML = $tableSizesHTML . "$tableName ($countResult), "; +if (is_readable($nax_db)) { + try { + $db_info_conn = new SQLite3($nax_db, SQLITE3_OPEN_READONLY); + $table_names_result = $db_info_conn->query("SELECT name FROM sqlite_master WHERE type='table'"); + while ($row = $table_names_result->fetchArray(SQLITE3_ASSOC)) { + $tableName = $row['name']; + $countResult = $db_info_conn->querySingle("SELECT COUNT(*) FROM $tableName"); + $tableSizesHTML = $tableSizesHTML . "$tableName ($countResult), "; + } + $db_info_conn->close(); + } catch (Exception $e) { + $tableSizesHTML = ''; + } } -$db_info_conn->close(); echo '