Skip to content

add live optimization progress update#368

Open
trean wants to merge 5 commits intomasterfrom
add-optimization-polling
Open

add live optimization progress update#368
trean wants to merge 5 commits intomasterfrom
add-optimization-polling

Conversation

@trean
Copy link
Copy Markdown
Contributor

@trean trean commented Apr 8, 2026

This PR adds live updating of ongoing optimization progress.

The next description is generated with Copilot. It looks correct to me:

Polling and Data Fetching Improvements:

  • Added a polling mechanism that periodically refreshes data only while optimizations are running and the tab is visible, using a configurable poll interval (POLL_ACTIVE_MS).
  • Refactored the data fetching logic into an async runFetch function that uses AbortController to cancel in-flight requests when a new fetch is triggered or the component unmounts, preventing race conditions and memory leaks.
  • Integrated browser tab visibility handling: polling is paused when the browser tab is hidden and resumes if there are running optimizations when the tab becomes visible again.

Component Lifecycle and Cleanup:

  • Ensured all timeouts and pending requests are properly cleared when the component unmounts or the collection changes, improving resource management.

My initial prompts to ai:

  1. Is there a performant way to add a live update of an ongoing optimization?
  2. Problem:
    ProgressGrid shows an optimization progress. But if there is an ongoing optimization, the status won't. Please add polling to the Optimizations component every 10s for ongoing optimization.

Poll only when something is running — After each response, if result.running (or your equivalent) is non-empty, schedule the next fetch in N seconds; if idle/empty, stop or use a much longer interval. That avoids hammering the API when nothing is changing.
Respect tab visibility — Use the Page Visibility API: pause or slow polling when document.hidden is true.
Single in-flight request — Ignore starting a new poll tick if the previous request hasn’t finished, or abort the previous request when starting a new one (AbortController), so you don’t queue traffic.
Reasonable interval — Often 2–5s while optimizing is enough; sub-second is usually unnecessary load.
Clean up on unmount — Clear setInterval / setTimeout and abort fetches so leaving the page stops all requests.
ProgressGrid and Timeline already react to data changes; you only need the parent (Optimizations) to call fetchData on that schedule (or use a data library that does refetch intervals for you).

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds live progress updates to the Collections “Optimizations” view by introducing conditional polling while optimizations are running, with request cancellation and tab-visibility awareness to reduce unnecessary network traffic.

Changes:

  • Introduced a polling loop that re-fetches optimizations only while result.running is non-empty and the tab is visible.
  • Refactored fetching into an async runFetch that aborts in-flight requests via AbortController.
  • Added cleanup for timeouts/requests on unmount and when collectionName changes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/components/Collections/Optimizations/Optimizations.jsx
Comment thread src/components/Collections/Optimizations/Optimizations.jsx
Comment thread src/components/Collections/Optimizations/Optimizations.jsx
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/components/Collections/Optimizations/Optimizations.jsx
Comment thread src/components/Collections/Optimizations/Optimizations.test.jsx
@generall generall changed the base branch from optimization-progress-summary to master April 10, 2026 17:22
@generall generall force-pushed the add-optimization-polling branch from 0a6bbac to d3e1ef7 Compare April 10, 2026 17:23
Copy link
Copy Markdown
Member

@generall generall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there are a few problems:

  • there are no refresh animation
  • logic of stopping pooling is inconsistent - it should either always refresh or not refresh. Current logic stop refreshing if everything is optimized, but in practice optimizations can start again at any moment. Refresh should either be always on or there should be a button to stop it
  • selection of the optimization tasks is lost on refresh

@trean trean force-pushed the add-optimization-polling branch from d3e1ef7 to ae4c6b0 Compare April 10, 2026 20:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants