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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion site/src/pages/WorkspacesPage/WorkspacesPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,24 @@ const WorkspacesPage: FC = () => {
const { data, error, refetch } = useQuery({
...workspacesQueryOptions,
refetchInterval: ({ state }) => {
return state.error ? false : 5_000;
if (state.error) return false;

// Check if any workspace has an active build
const hasActiveBuilds = state.data?.workspaces?.some((workspace) => {
const status = workspace.latest_build.status;
return [
"canceling",
"deleting",
"pending",
"starting",
"stopping",
].includes(status);
});

// Poll every 5s if there are active builds, otherwise every 30s
return hasActiveBuilds ? 5_000 : 30_000;
},
refetchIntervalInBackground: false, // Stop polling when tab is inactive
});

const [checkedWorkspaces, setCheckedWorkspaces] = useState<
Expand Down
Loading