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

Commit1195f31

Browse files
authored
chore(site): reduce fetch interval on workspaces page (#18725)
Relates tocoder/internal#720* Reduces workspaces data refetch interval if no builds are pending* Sets `refetchOnWindowFocus: always` to mitigate impact of reduced polling duration
1 parent8202514 commit1195f31

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

‎site/src/pages/WorkspacesPage/WorkspacesPage.tsx

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { getErrorDetail, getErrorMessage } from "api/errors";
22
import{workspacePermissionsByOrganization}from"api/queries/organizations";
33
import{templates}from"api/queries/templates";
44
import{workspaces}from"api/queries/workspaces";
5-
importtype{Workspace}from"api/typesGenerated";
5+
importtype{Workspace,WorkspaceStatus}from"api/typesGenerated";
66
import{useFilter}from"components/Filter/Filter";
77
import{useUserFilterMenu}from"components/Filter/UserFilter";
88
import{displayError}from"components/GlobalSnackbar/utils";
@@ -22,6 +22,18 @@ import { WorkspacesPageView } from "./WorkspacesPageView";
2222
import{useBatchActions}from"./batchActions";
2323
import{useStatusFilterMenu,useTemplateFilterMenu}from"./filter/menus";
2424

25+
// To reduce the number of fetches, we reduce the fetch interval if there are no
26+
// active workspace builds.
27+
constACTIVE_BUILD_STATUSES:WorkspaceStatus[]=[
28+
"canceling",
29+
"deleting",
30+
"pending",
31+
"starting",
32+
"stopping",
33+
];
34+
constACTIVE_BUILDS_REFRESH_INTERVAL=5_000;
35+
constNO_ACTIVE_BUILDS_REFRESH_INTERVAL=30_000;
36+
2537
functionuseSafeSearchParams(){
2638
// Have to wrap setSearchParams because React Router doesn't make sure that
2739
// the function's memory reference stays stable on each render, even though
@@ -78,8 +90,23 @@ const WorkspacesPage: FC = () => {
7890
const{ data, error, refetch}=useQuery({
7991
...workspacesQueryOptions,
8092
refetchInterval:({ state})=>{
81-
returnstate.error ?false :5_000;
93+
if(state.error)returnfalse;
94+
95+
// Default to 5s interval until first fetch completes
96+
if(!state.data)returnACTIVE_BUILDS_REFRESH_INTERVAL;
97+
98+
// Check if any workspace has an active build
99+
consthasActiveBuilds=state.data.workspaces?.some((workspace)=>{
100+
conststatus=workspace.latest_build.status;
101+
returnACTIVE_BUILD_STATUSES.includes(status);
102+
});
103+
104+
// Poll every 5s if there are active builds, otherwise every 30s
105+
returnhasActiveBuilds
106+
?ACTIVE_BUILDS_REFRESH_INTERVAL
107+
:NO_ACTIVE_BUILDS_REFRESH_INTERVAL;
82108
},
109+
refetchOnWindowFocus:"always",
83110
});
84111

85112
const[checkedWorkspaces,setCheckedWorkspaces]=useState<

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp