Skip to content

chore(site): reduce fetch interval on workspaces page #18725

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 8, 2025

Conversation

johnstcn
Copy link
Member

@johnstcn johnstcn commented Jul 2, 2025

Relates to coder/internal#720

The workspaces query fetches a lot of information. We can probably reduce the frequency at which we fetch data by polling less often if no workspace builds are in 'intermediate' states.

@johnstcn johnstcn requested a review from a team July 2, 2025 17:34
@johnstcn johnstcn self-assigned this Jul 2, 2025
@johnstcn johnstcn requested review from jaaydenh and removed request for a team July 2, 2025 17:34
@johnstcn johnstcn requested a review from Copilot July 3, 2025 16:06
Copy link
Contributor

@Copilot 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

This PR reduces the polling frequency on the Workspaces page by dynamically adjusting the refetch interval:

  • Polls every 5s when any workspace build is in an intermediate state, otherwise every 30s.
  • Disables polling on errors and when the tab is inactive.
Comments suppressed due to low confidence (2)

site/src/pages/WorkspacesPage/WorkspacesPage.tsx:80

  • [nitpick] Consider adding unit or integration tests to verify that the polling interval switches correctly based on error states and active build presence.
		refetchInterval: ({ state }) => {

site/src/pages/WorkspacesPage/WorkspacesPage.tsx:85

  • workspace.latest_build may be undefined, causing runtime errors; use optional chaining (e.g., workspace.latest_build?.status) or provide a default value to guard against missing builds.
				const status = workspace.latest_build.status;

@johnstcn johnstcn requested review from a team and Kira-Pilot and removed request for jaaydenh, a team and Kira-Pilot July 7, 2025 10:19
Copy link
Member

@aslilac aslilac left a comment

Choose a reason for hiding this comment

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

seems legit

},
refetchOnWindowFocus: "always",
Copy link
Member Author

@johnstcn johnstcn Jul 8, 2025

Choose a reason for hiding this comment

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

review: refetchInterval does not execute while the tab is in the background, so the reduced refresh interval is more noticeable if you switch to a different tab and then switch back. Adding refetchOnWindowFocus here seems like a good way to ensure that a user sees fresh data sooner. Alternatively, we could set refetchIntervalInBackground but we then have to reason about two separate refresh loops. It also means that background Coder tabs will poll continuously, which does not seem desirable.

@johnstcn johnstcn merged commit 1195f31 into main Jul 8, 2025
31 of 33 checks passed
@johnstcn johnstcn deleted the cj/site/reduce-workspaces-fetch-interval branch July 8, 2025 10:00
@github-actions github-actions bot locked and limited conversation to collaborators Jul 8, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants