mirror of
https://github.com/MarekWo/mc-webui.git
synced 2026-08-12 11:42:56 +02:00
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:
+27
-2
@@ -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>
|
||||
`;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user