Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
johnstcn merged 5 commits intomainfromcj/site/reduce-workspaces-fetch-interval
Jul 8, 2025
Merged
Changes fromall 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
31 changes: 29 additions & 2 deletionssite/src/pages/WorkspacesPage/WorkspacesPage.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,7 +2,7 @@ import { getErrorDetail, getErrorMessage } from "api/errors";
import { workspacePermissionsByOrganization } from "api/queries/organizations";
import { templates } from "api/queries/templates";
import { workspaces } from "api/queries/workspaces";
import type { Workspace } from "api/typesGenerated";
import type { Workspace, WorkspaceStatus } from "api/typesGenerated";
import { useFilter } from "components/Filter/Filter";
import { useUserFilterMenu } from "components/Filter/UserFilter";
import { displayError } from "components/GlobalSnackbar/utils";
Expand All@@ -22,6 +22,18 @@ import { WorkspacesPageView } from "./WorkspacesPageView";
import { useBatchActions } from "./batchActions";
import { useStatusFilterMenu, useTemplateFilterMenu } from "./filter/menus";

// To reduce the number of fetches, we reduce the fetch interval if there are no
// active workspace builds.
const ACTIVE_BUILD_STATUSES: WorkspaceStatus[] = [
"canceling",
"deleting",
"pending",
"starting",
"stopping",
];
const ACTIVE_BUILDS_REFRESH_INTERVAL = 5_000;
const NO_ACTIVE_BUILDS_REFRESH_INTERVAL = 30_000;

function useSafeSearchParams() {
// Have to wrap setSearchParams because React Router doesn't make sure that
// the function's memory reference stays stable on each render, even though
Expand DownExpand Up@@ -78,8 +90,23 @@ const WorkspacesPage: FC = () => {
const { data, error, refetch } = useQuery({
...workspacesQueryOptions,
refetchInterval: ({ state }) => {
return state.error ? false : 5_000;
if (state.error) return false;

// Default to 5s interval until first fetch completes
if (!state.data) return ACTIVE_BUILDS_REFRESH_INTERVAL;

// Check if any workspace has an active build
const hasActiveBuilds = state.data.workspaces?.some((workspace) => {
const status = workspace.latest_build.status;
return ACTIVE_BUILD_STATUSES.includes(status);
});

// Poll every 5s if there are active builds, otherwise every 30s
return hasActiveBuilds
? ACTIVE_BUILDS_REFRESH_INTERVAL
: NO_ACTIVE_BUILDS_REFRESH_INTERVAL;
},
refetchOnWindowFocus: "always",
Copy link
MemberAuthor

@johnstcnjohnstcnJul 8, 2025
edited
Loading

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. AddingrefetchOnWindowFocus here seems like a good way to ensure that a user sees fresh data sooner. Alternatively, we could setrefetchIntervalInBackground 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.

});

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

[8]ページ先頭

©2009-2025 Movatter.jp