Skip to content

Commit c868fc9

Browse files
committed
Only do 1 api call based on experiment
1 parent 5bb44e8 commit c868fc9

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

site/src/contexts/ProxyContext.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ export const ProxyProvider: FC<PropsWithChildren> = ({ children }) => {
5656
setProxy(preferred)
5757
}
5858

59+
const dashboard = useDashboard()
60+
const experimentEnabled = !dashboard?.experiments.includes("moons")
5961
const queryKey = ["get-regions"]
6062
const { error: regionsError, isLoading: regionsLoading } = useQuery({
6163
queryKey,
@@ -66,13 +68,13 @@ export const ProxyProvider: FC<PropsWithChildren> = ({ children }) => {
6668
onSuccess: (data) => {
6769
setAndSaveProxy(data.regions, proxy.selectedProxy)
6870
},
71+
enabled: experimentEnabled,
6972
})
7073

7174
// ******************************* //
7275
// ** This code can be removed **
7376
// ** when the experimental is **
7477
// ** dropped ** //
75-
const dashboard = useDashboard()
7678
const appHostQueryKey = ["get-application-host"]
7779
const {
7880
data: applicationHostResult,
@@ -81,11 +83,12 @@ export const ProxyProvider: FC<PropsWithChildren> = ({ children }) => {
8183
} = useQuery({
8284
queryKey: appHostQueryKey,
8385
queryFn: getApplicationsHost,
86+
enabled: !experimentEnabled,
8487
})
8588

8689
// If the experiment is disabled, then make the setState do a noop.
8790
// This preserves an empty state, which is the default behavior.
88-
if (!dashboard?.experiments.includes("moons")) {
91+
if (!experimentEnabled) {
8992
const value = getPreferredProxy([])
9093

9194
return (

0 commit comments

Comments
 (0)