fix: brain polling — update individual items instead of full reload
Polls only pending/processing items by ID every 4s instead of reloading the entire list every 3s. Prevents screen flashing. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -217,25 +217,37 @@
|
|||||||
function startPolling() {
|
function startPolling() {
|
||||||
stopPolling();
|
stopPolling();
|
||||||
pollTimer = setInterval(async () => {
|
pollTimer = setInterval(async () => {
|
||||||
const hasPending = items.some(i => i.processing_status === 'pending' || i.processing_status === 'processing');
|
const pendingIds = items
|
||||||
if (hasPending) {
|
.filter(i => i.processing_status === 'pending' || i.processing_status === 'processing')
|
||||||
await loadItems();
|
.map(i => i.id);
|
||||||
// Update selected item if it was pending
|
|
||||||
if (selectedItem) {
|
if (pendingIds.length === 0) {
|
||||||
const updated = items.find(i => i.id === selectedItem!.id);
|
|
||||||
if (updated) selectedItem = updated;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
stopPolling();
|
stopPolling();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}, 3000);
|
|
||||||
|
// Poll each pending item individually instead of reloading everything
|
||||||
|
for (const id of pendingIds) {
|
||||||
|
try {
|
||||||
|
const updated = await api(`/items/${id}`);
|
||||||
|
const idx = items.findIndex(i => i.id === id);
|
||||||
|
if (idx !== -1) {
|
||||||
|
items[idx] = updated;
|
||||||
|
items = items; // trigger reactivity
|
||||||
|
}
|
||||||
|
if (selectedItem?.id === id) {
|
||||||
|
selectedItem = updated;
|
||||||
|
}
|
||||||
|
} catch { /* item might be gone */ }
|
||||||
|
}
|
||||||
|
}, 4000);
|
||||||
}
|
}
|
||||||
|
|
||||||
function stopPolling() {
|
function stopPolling() {
|
||||||
if (pollTimer) { clearInterval(pollTimer); pollTimer = null; }
|
if (pollTimer) { clearInterval(pollTimer); pollTimer = null; }
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start polling after capture
|
// Start polling when pending items exist
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
const hasPending = items.some(i => i.processing_status === 'pending' || i.processing_status === 'processing');
|
const hasPending = items.some(i => i.processing_status === 'pending' || i.processing_status === 'processing');
|
||||||
if (hasPending && !pollTimer) startPolling();
|
if (hasPending && !pollTimer) startPolling();
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user