Codebase review fixes: stability, performance, quality improvements

Stability: Add outer try/except/finally with _running=False cleanup to all 6
processing loop methods (live, color_strip, effect, audio, composite, mapped).
Add exponential backoff on consecutive capture errors in live_stream. Move
audio stream.stop() outside lock scope.

Performance: Replace per-pixel Python loop with np.array().tobytes() in
ddp_client. Vectorize pixelate filter with cv2.resize down+up. Vectorize
gradient rendering with np.searchsorted.

Frontend: Add lockBody/unlockBody re-entrancy counter. Add {once:true} to
fetchWithAuth abort listener. Null ws.onclose before ws.close() in LED preview.

Backend: Remove auth token prefix from log messages. Add atomic_write_json
helper (tempfile + os.replace) and update all 10 stores. Add name uniqueness
checks to all update methods. Fix DELETE status codes to 204 in audio_sources
and value_sources. Fix get_source() silent bug in color_strip_sources.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-26 18:23:04 +03:00
parent bafd8b4130
commit 9cfe628cc5
30 changed files with 922 additions and 779 deletions

View File

@@ -36,7 +36,7 @@ export async function fetchWithAuth(url, options = {}) {
for (let attempt = 0; attempt < maxAttempts; attempt++) {
const controller = new AbortController();
if (fetchOpts.signal) {
fetchOpts.signal.addEventListener('abort', () => controller.abort());
fetchOpts.signal.addEventListener('abort', () => controller.abort(), { once: true });
}
const timer = setTimeout(() => controller.abort(), timeout);
try {

View File

@@ -56,17 +56,26 @@ export function setupBackdropClose(modal, closeFn) {
modal._backdropCloseSetup = true;
}
let _lockCount = 0;
let _savedScrollY = 0;
export function lockBody() {
const scrollY = window.scrollY;
document.body.style.top = `-${scrollY}px`;
document.body.classList.add('modal-open');
if (_lockCount === 0) {
_savedScrollY = window.scrollY;
document.body.style.top = `-${_savedScrollY}px`;
document.body.classList.add('modal-open');
}
_lockCount++;
}
export function unlockBody() {
const scrollY = parseInt(document.body.style.top || '0', 10) * -1;
document.body.classList.remove('modal-open');
document.body.style.top = '';
window.scrollTo(0, scrollY);
if (_lockCount <= 0) return;
_lockCount--;
if (_lockCount === 0) {
document.body.classList.remove('modal-open');
document.body.style.top = '';
window.scrollTo(0, _savedScrollY);
}
}
export function openLightbox(imageSrc, statsHtml) {

View File

@@ -1102,6 +1102,7 @@ function connectLedPreviewWS(targetId) {
function disconnectLedPreviewWS(targetId) {
const ws = ledPreviewWebSockets[targetId];
if (ws) {
ws.onclose = null;
ws.close();
delete ledPreviewWebSockets[targetId];
}