Skip to content

Commit 91e20e4

Browse files
committed
Monitoring UI: preserve recent queries table during WebSocket reconnects
- Cache the last non-empty recent queries data in the dashboard JS. - Prevent the recent queries section from disappearing during WebSocket reconnects or temporary data gaps. - Only update the table when new, non-empty data arrives.
1 parent 00914a4 commit 91e20e4

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

dnscrypt-proxy/static/js/monitoring.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ function handleError(error) {
6464
}
6565
}
6666

67+
// Cache for the last non-empty recent queries
68+
let lastRecentQueries = [];
69+
6770
// Safe update function that handles missing data
6871
function safeUpdateDashboard(data) {
6972
try {
@@ -142,9 +145,14 @@ function safeUpdateDashboard(data) {
142145

143146
// Update recent queries table
144147
const queriesTable = document.getElementById('queries-table').getElementsByTagName('tbody')[0];
148+
let queriesToShow = lastRecentQueries;
149+
if (data.recent_queries && Array.isArray(data.recent_queries) && data.recent_queries.length > 0) {
150+
lastRecentQueries = data.recent_queries;
151+
queriesToShow = lastRecentQueries;
152+
}
145153
queriesTable.innerHTML = '';
146-
if (data.recent_queries && Array.isArray(data.recent_queries)) {
147-
data.recent_queries.slice().reverse().forEach(query => {
154+
if (queriesToShow && Array.isArray(queriesToShow)) {
155+
queriesToShow.slice().reverse().forEach(query => {
148156
const row = queriesTable.insertRow();
149157
row.insertCell(0).textContent = query.timestamp ? new Date(query.timestamp).toLocaleTimeString() : '-';
150158
row.insertCell(1).textContent = query.domain || '-';

0 commit comments

Comments
 (0)