fix: prevent page hang when device channel queries block

/api/messages and /api/messages/updates called get_channels_cached()
which blocks on device communication when cache is cold (up to 240s).
Now uses DB-cached channels for pkt_payload computation instead.

Frontend loadMessages() now has a 15s timeout with auto-retry
and clears the loading spinner on error instead of leaving it
spinning indefinitely.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
MarekWo
2026-03-23 21:26:26 +01:00
parent 343b6f40a8
commit dfc3b1403a
2 changed files with 50 additions and 24 deletions
+27 -2
View File
@@ -854,7 +854,12 @@ async function loadMessages() {
url += '&days=7';
}
const response = await fetch(url);
// Add timeout to prevent hanging spinner
const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), 15000);
const response = await fetch(url, { signal: controller.signal });
clearTimeout(timeoutId);
const data = await response.json();
if (data.success) {
@@ -863,11 +868,31 @@ async function loadMessages() {
updateLastRefresh();
} else {
showNotification('Error loading messages: ' + data.error, 'danger');
clearLoadingSpinner();
}
} catch (error) {
console.error('Error loading messages:', error);
updateStatus('disconnected');
showNotification('Failed to load messages', 'danger');
clearLoadingSpinner();
if (error.name === 'AbortError') {
showNotification('Loading messages timed out — retrying...', 'warning');
setTimeout(loadMessages, 2000);
} else {
showNotification('Failed to load messages', 'danger');
}
}
}
function clearLoadingSpinner() {
const container = document.getElementById('messagesList');
if (container && container.querySelector('.spinner-border')) {
container.innerHTML = `
<div class="empty-state">
<i class="bi bi-exclamation-triangle"></i>
<p>Could not load messages</p>
<small>Will retry automatically</small>
</div>
`;
}
}