From 5e7d3c911c64255217a0a1dedbdf91d9718ecb8e Mon Sep 17 00:00:00 2001 From: Tim Roes Date: Wed, 14 Jun 2023 15:30:37 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=AA=9F=20=F0=9F=8E=89=20Add=20less=20ofte?= =?UTF-8?q?n=20appearing=20update=20notification=20(#7211)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/hooks/services/useBuildUpdateCheck.ts | 23 +++++++++++++++---- .../src/packages/cloud/cloudRoutes.tsx | 3 +++ airbyte-webapp/src/pages/routes.tsx | 3 +++ 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/airbyte-webapp/src/hooks/services/useBuildUpdateCheck.ts b/airbyte-webapp/src/hooks/services/useBuildUpdateCheck.ts index 85645f6acc2..300a1de7057 100644 --- a/airbyte-webapp/src/hooks/services/useBuildUpdateCheck.ts +++ b/airbyte-webapp/src/hooks/services/useBuildUpdateCheck.ts @@ -1,6 +1,7 @@ import { useEffect } from "react"; import { useIntl } from "react-intl"; -import { fromEvent, interval, merge, throttleTime } from "rxjs"; +import { useEffectOnce } from "react-use"; +import { filter, fromEvent, interval, merge } from "rxjs"; import { useAppMonitoringService } from "./AppMonitoringService"; import { useNotificationService } from "./Notification"; @@ -9,8 +10,10 @@ interface BuildInfo { build: string; } +const LAST_UPDATE_CHECK_KEY = "lastUpdateCheckTimestamp"; + const INTERVAL = 60_000; -const MINIMUM_WAIT_BEFORE_REFETCH = 10_000; +const MINIMUM_WAIT_BEFORE_REFETCH = 3 * 24 * 60 * 60 * 1000; // 3 days /** * This hook sets up a check to /buildInfo.json, which is generated by the build system on every build @@ -22,12 +25,24 @@ export const useBuildUpdateCheck = () => { const { registerNotification } = useNotificationService(); const { trackError } = useAppMonitoringService(); + useEffectOnce(() => { + // Set the last update check to the timestamp when the page is loaded, so we won't check for another x days from now + window.sessionStorage.setItem(LAST_UPDATE_CHECK_KEY, String(Date.now())); + }); + useEffect(() => { // Trigger the check every ${INTERVAL} milliseconds or whenever the window regains focus again const subscription = merge(interval(INTERVAL), fromEvent(window, "focus")) - // Throttle it to maximum once every 10 seconds - .pipe(throttleTime(MINIMUM_WAIT_BEFORE_REFETCH)) + .pipe( + filter(() => { + // Only run actual check if the previous check was more than MINIMUM_WAIT_BEFORE_REFETCH ago + const lastUpdateCheck = window.sessionStorage.getItem(LAST_UPDATE_CHECK_KEY); + return !lastUpdateCheck || Date.now() - Number(lastUpdateCheck) > MINIMUM_WAIT_BEFORE_REFETCH; + }) + ) .subscribe(async () => { + window.sessionStorage.setItem(LAST_UPDATE_CHECK_KEY, String(Date.now())); + try { // Fetch the buildInfo.json file without using any browser cache const buildInfo: BuildInfo = await fetch("/buildInfo.json", { cache: "no-store" }).then((resp) => diff --git a/airbyte-webapp/src/packages/cloud/cloudRoutes.tsx b/airbyte-webapp/src/packages/cloud/cloudRoutes.tsx index a74b41d62dc..00ebc96f9a2 100644 --- a/airbyte-webapp/src/packages/cloud/cloudRoutes.tsx +++ b/airbyte-webapp/src/packages/cloud/cloudRoutes.tsx @@ -5,6 +5,7 @@ import { ApiErrorBoundary } from "components/common/ApiErrorBoundary"; import LoadingPage from "components/LoadingPage"; import { useAnalyticsIdentifyUser, useAnalyticsRegisterValues } from "core/services/analytics/useAnalyticsService"; +import { useBuildUpdateCheck } from "hooks/services/useBuildUpdateCheck"; import { useQuery } from "hooks/useQuery"; import { useAuthService } from "packages/cloud/services/auth/AuthService"; import ConnectorBuilderRoutes from "pages/connectorBuilder/ConnectorBuilderRoutes"; @@ -129,6 +130,8 @@ export const Routing: React.FC = () => { const workspaceId = useCurrentWorkspaceId(); const { pathname } = useLocation(); + useBuildUpdateCheck(); + // invalidate everything in the workspace scope when the workspaceId changes useInvalidateAllWorkspaceScopeOnChange(workspaceId); diff --git a/airbyte-webapp/src/pages/routes.tsx b/airbyte-webapp/src/pages/routes.tsx index f9eaee8b748..e0edd3d2064 100644 --- a/airbyte-webapp/src/pages/routes.tsx +++ b/airbyte-webapp/src/pages/routes.tsx @@ -5,6 +5,7 @@ import { ApiErrorBoundary } from "components/common/ApiErrorBoundary"; import { useAnalyticsIdentifyUser, useAnalyticsRegisterValues } from "core/services/analytics"; import { useApiHealthPoll } from "hooks/services/Health"; +import { useBuildUpdateCheck } from "hooks/services/useBuildUpdateCheck"; import { useCurrentWorkspace } from "hooks/services/useWorkspace"; import { useInvalidateAllWorkspaceScopeOnChange, useListWorkspaces } from "services/workspaces/WorkspacesService"; import { CompleteOauthRequest } from "views/CompleteOauthRequest"; @@ -112,6 +113,8 @@ const RoutingWithWorkspace: React.FC<{ element?: JSX.Element }> = ({ element }) }; export const Routing: React.FC = () => { + useBuildUpdateCheck(); + // TODO: Remove this after it is verified there are no problems with current routing const OldRoutes = useMemo( () =>