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

Commit1587c7f

Browse files
committed
chore: reduce requests the dashboard makes from seeded data
We already inject all of this content in `index.html`.There was also a bug with displaying a loading indicator whenthe workspace proxies endpoint 404s.
1 parent7bd1b3b commit1587c7f

File tree

4 files changed

+54
-11
lines changed

4 files changed

+54
-11
lines changed

‎site/src/api/queries/appearance.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,22 @@ import { getMetadataAsJSON } from "utils/metadata";
66
constinitialAppearanceData=getMetadataAsJSON<AppearanceConfig>("appearance");
77
constappearanceConfigKey=["appearance"]asconst;
88

9-
exportconstappearance=():UseQueryOptions<AppearanceConfig>=>{
10-
return{
9+
exportconstappearance=()=>{
10+
constopts:UseQueryOptions<AppearanceConfig>={
1111
queryKey:["appearance"],
1212
initialData:initialAppearanceData,
1313
queryFn:()=>API.getAppearance(),
1414
};
15+
// If we have initial appearance data, we don't want to fetch
16+
// the user again. We already have it!
17+
if(initialAppearanceData){
18+
opts.cacheTime=Infinity;
19+
opts.staleTime=Infinity;
20+
opts.refetchOnMount=false;
21+
opts.refetchOnReconnect=false;
22+
opts.refetchOnWindowFocus=false;
23+
}
24+
returnopts;
1525
};
1626

1727
exportconstupdateAppearance=(queryClient:QueryClient)=>{

‎site/src/api/queries/buildInfo.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,20 @@ import { getMetadataAsJSON } from "utils/metadata";
66
constinitialBuildInfoData=getMetadataAsJSON<BuildInfoResponse>("build-info");
77
constbuildInfoKey=["buildInfo"]asconst;
88

9-
exportconstbuildInfo=():UseQueryOptions<BuildInfoResponse>=>{
10-
return{
9+
exportconstbuildInfo=()=>{
10+
constopts:UseQueryOptions<BuildInfoResponse>={
1111
queryKey:buildInfoKey,
1212
initialData:initialBuildInfoData,
1313
queryFn:()=>API.getBuildInfo(),
1414
};
15+
// If we have initial build info data, we don't want to fetch
16+
// the user again. We already have it!
17+
if(initialBuildInfoData){
18+
opts.cacheTime=Infinity;
19+
opts.staleTime=Infinity;
20+
opts.refetchOnMount=false;
21+
opts.refetchOnReconnect=false;
22+
opts.refetchOnWindowFocus=false;
23+
}
24+
returnopts
1525
};

‎site/src/api/queries/users.ts

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ export const updateRoles = (queryClient: QueryClient) => {
112112
};
113113
};
114114

115+
constinitialUserData=getMetadataAsJSON<User>("user");
116+
115117
exportconstauthMethods=()=>{
116118
return{
117119
// Even the endpoint being /users/authmethods we don't want to revalidate it
@@ -121,18 +123,26 @@ export const authMethods = () => {
121123
};
122124
};
123125

124-
constinitialUserData=getMetadataAsJSON<User>("user");
125-
126126
constmeKey=["me"];
127127

128-
exportconstme=():UseQueryOptions<User>&{
129-
queryKey:QueryKey;
130-
}=>{
131-
return{
128+
exportconstme=()=>{
129+
constopts:UseQueryOptions<User>&{
130+
queryKey:QueryKey;
131+
}={
132132
queryKey:meKey,
133133
initialData:initialUserData,
134134
queryFn:API.getAuthenticatedUser,
135135
};
136+
// If we have initial user data, we don't want to fetch
137+
// the user again. We already have it!
138+
if(initialUserData){
139+
opts.cacheTime=Infinity;
140+
opts.staleTime=Infinity;
141+
opts.refetchOnMount=false;
142+
opts.refetchOnReconnect=false;
143+
opts.refetchOnWindowFocus=false;
144+
}
145+
returnopts
136146
};
137147

138148
exportfunctionapiKey():UseQueryOptions<GenerateAPIKeyResponse>{
@@ -142,8 +152,14 @@ export function apiKey(): UseQueryOptions<GenerateAPIKeyResponse> {
142152
};
143153
}
144154

145-
exportconsthasFirstUser=()=>{
155+
exportconsthasFirstUser=():UseQueryOptions<boolean>=>{
146156
return{
157+
// If there is initial user data, we don't want to make
158+
// this request. It's a waste!
159+
cacheTime:Infinity,
160+
staleTime:Infinity,
161+
initialData:Boolean(initialUserData),
162+
147163
queryKey:["hasFirstUser"],
148164
queryFn:API.hasFirstUser,
149165
};

‎site/src/modules/dashboard/Navbar/NavbarView.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,13 @@ const ProxyMenu: FC<ProxyMenuProps> = ({ proxyContextValue }) => {
235235
returnproxy.healthy&&latency!==undefined&&latency.at<refetchDate;
236236
};
237237

238+
// This endpoint returns a 404 when not using enterprise.
239+
// If we don't return null, then it looks like this is
240+
// loading forever!
241+
if(proxyContextValue.error){
242+
returnnull
243+
}
244+
238245
if(isLoading){
239246
return(
240247
<Skeleton

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp