From a7676633fcbd79245150aae2bf02beae45d54069 Mon Sep 17 00:00:00 2001 From: Andrew Farries Date: Mon, 28 Nov 2022 18:47:11 +0000 Subject: [PATCH] Remove client side eval of `slow_database` flag The logic of checking the feature flag has moved to the backend (`proxy`) so we don't need this logic on the dashboard anymore. --- components/dashboard/src/App.tsx | 8 ++------ .../dashboard/src/contexts/FeatureFlagContext.tsx | 5 ----- components/dashboard/src/service/service.tsx | 14 ++------------ .../src/messaging/browser/connection.ts | 7 +++---- 4 files changed, 7 insertions(+), 27 deletions(-) diff --git a/components/dashboard/src/App.tsx b/components/dashboard/src/App.tsx index a850f01747a735..4a8d0835bc8a0d 100644 --- a/components/dashboard/src/App.tsx +++ b/components/dashboard/src/App.tsx @@ -12,7 +12,7 @@ import { Login } from "./Login"; import { UserContext } from "./user-context"; import { getSelectedTeamSlug, TeamsContext } from "./teams/teams-context"; import { ThemeContext } from "./theme-context"; -import { getGitpodService, initGitPodService } from "./service/service"; +import { getGitpodService } from "./service/service"; import { shouldSeeWhatsNew, WhatsNew } from "./whatsnew/WhatsNew"; import gitpodIcon from "./icons/gitpod.svg"; import { ErrorCodes } from "@gitpod/gitpod-protocol/lib/messaging/error"; @@ -162,7 +162,7 @@ function App() { const { user, setUser, refreshUserBillingMode } = useContext(UserContext); const { teams, setTeams } = useContext(TeamsContext); const { setIsDark } = useContext(ThemeContext); - const { usePublicApiTeamsService, useSlowDatabase } = useContext(FeatureFlagContext); + const { usePublicApiTeamsService } = useContext(FeatureFlagContext); const [loading, setLoading] = useState(true); const [isWhatsNewShown, setWhatsNewShown] = useState(false); @@ -170,10 +170,6 @@ function App() { const [isSetupRequired, setSetupRequired] = useState(false); const history = useHistory(); - useEffect(() => { - initGitPodService(useSlowDatabase); - }, [useSlowDatabase]); - useEffect(() => { (async () => { var user: User | undefined; diff --git a/components/dashboard/src/contexts/FeatureFlagContext.tsx b/components/dashboard/src/contexts/FeatureFlagContext.tsx index dd1717ed3bdd6f..4d9df55c9ba856 100644 --- a/components/dashboard/src/contexts/FeatureFlagContext.tsx +++ b/components/dashboard/src/contexts/FeatureFlagContext.tsx @@ -21,14 +21,12 @@ const FeatureFlagContext = createContext<{ showUseLastSuccessfulPrebuild: boolean; usePublicApiTeamsService: boolean; enablePersonalAccessTokens: boolean; - useSlowDatabase: boolean; }>({ showPersistentVolumeClaimUI: false, showUsageView: false, showUseLastSuccessfulPrebuild: false, usePublicApiTeamsService: false, enablePersonalAccessTokens: false, - useSlowDatabase: false, }); const FeatureFlagContextProvider: React.FC = ({ children }) => { @@ -42,7 +40,6 @@ const FeatureFlagContextProvider: React.FC = ({ children }) => { const [showUseLastSuccessfulPrebuild, setShowUseLastSuccessfulPrebuild] = useState(false); const [usePublicApiTeamsService, setUsePublicApiTeamsService] = useState(false); const [enablePersonalAccessTokens, setPersonalAccessTokensEnabled] = useState(false); - const [useSlowDatabase, setUseSlowDatabase] = useState(false); useEffect(() => { if (!user) return; @@ -53,7 +50,6 @@ const FeatureFlagContextProvider: React.FC = ({ children }) => { showUseLastSuccessfulPrebuild: { defaultValue: false, setter: setShowUseLastSuccessfulPrebuild }, publicApiExperimentalTeamsService: { defaultValue: false, setter: setUsePublicApiTeamsService }, personalAccessTokensEnabled: { defaultValue: false, setter: setPersonalAccessTokensEnabled }, - slow_database: { defaultValue: false, setter: setUseSlowDatabase }, }; for (const [flagName, config] of Object.entries(featureFlags)) { @@ -98,7 +94,6 @@ const FeatureFlagContextProvider: React.FC = ({ children }) => { showUseLastSuccessfulPrebuild, usePublicApiTeamsService, enablePersonalAccessTokens, - useSlowDatabase, }} > {children} diff --git a/components/dashboard/src/service/service.tsx b/components/dashboard/src/service/service.tsx index f5dc5e0be89de9..efda93aa80e011 100644 --- a/components/dashboard/src/service/service.tsx +++ b/components/dashboard/src/service/service.tsx @@ -19,7 +19,7 @@ import { log } from "@gitpod/gitpod-protocol/lib/util/logging"; export const gitpodHostUrl = new GitpodHostUrl(window.location.toString()); -function createGitpodService(useSlowDatabase: boolean = false) { +function createGitpodService() { if (window.top !== window.self && process.env.NODE_ENV === "production") { const connection = createWindowMessageConnection("gitpodServer", window.parent, "*"); const factory = new JsonRpcProxyFactory(); @@ -48,7 +48,6 @@ function createGitpodService(use onListening: (socket) => { onReconnect = () => socket.reconnect(); }, - subProtocol: useSlowDatabase ? "slow-database" : undefined, }); return new GitpodServiceImpl(proxy, { onReconnect }); @@ -65,13 +64,4 @@ function getGitpodService(): GitpodService { return service; } -function initGitPodService(useSlowDatabase: boolean) { - const w = window as any; - const _gp = w._gp || (w._gp = {}); - if (window.location.search.includes("service=mock")) { - _gp.gitpodService = require("./service-mock").gitpodServiceMock; - } - _gp.gitpodService = createGitpodService(useSlowDatabase); -} - -export { getGitpodService, initGitPodService }; +export { getGitpodService }; diff --git a/components/gitpod-protocol/src/messaging/browser/connection.ts b/components/gitpod-protocol/src/messaging/browser/connection.ts index f02cd3b5278fa5..1ef3878449a806 100644 --- a/components/gitpod-protocol/src/messaging/browser/connection.ts +++ b/components/gitpod-protocol/src/messaging/browser/connection.ts @@ -16,7 +16,6 @@ import ReconnectingWebSocket, { Event } from "reconnecting-websocket"; export interface WebSocketOptions { onerror?: (event: Event) => void; onListening?: (socket: ReconnectingWebSocket) => void; - subProtocol?: string; } export class WebSocketConnectionProvider { @@ -63,7 +62,7 @@ export class WebSocketConnectionProvider { */ listen(handler: ConnectionHandler, eventHandler: ConnectionEventHandler, options?: WebSocketOptions): WebSocket { const url = handler.path; - const webSocket = this.createWebSocket(url, options); + const webSocket = this.createWebSocket(url); const logger = this.createLogger(); if (options && options.onerror) { @@ -87,8 +86,8 @@ export class WebSocketConnectionProvider { /** * Creates a web socket for the given url */ - createWebSocket(url: string, options?: WebSocketOptions): WebSocket { - return new ReconnectingWebSocket(url, options?.subProtocol, { + createWebSocket(url: string): WebSocket { + return new ReconnectingWebSocket(url, undefined, { maxReconnectionDelay: 10000, minReconnectionDelay: 1000, reconnectionDelayGrowFactor: 1.3,