From 22d37bda5d73c5ccb82f195b320b39ab0d38970f Mon Sep 17 00:00:00 2001 From: Jan Prochazka Date: Mon, 18 Jan 2021 17:34:20 +0100 Subject: [PATCH] optimalization --- packages/web/src/utility/globalState.js | 4 ++++ packages/web/src/widgets/WidgetContainer.js | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/web/src/utility/globalState.js b/packages/web/src/utility/globalState.js index 8975f652..a469046c 100644 --- a/packages/web/src/utility/globalState.js +++ b/packages/web/src/utility/globalState.js @@ -95,11 +95,15 @@ export { OpenedTabsProvider, useOpenedTabs, useSetOpenedTabs }; export function useUpdateDatabaseForTab(tabVisible, conid, database) { const connection = useConnectionInfo({ conid }); const setDb = useSetCurrentDatabase(); + const currentDb = useCurrentDatabase(); const previousTabVisible = usePrevious(!!(tabVisible && connection)); if (!conid || !database) return; if (!previousTabVisible && tabVisible && connection) { + if (currentDb && currentDb.connection && currentDb.connection._id == conid && currentDb.name == database) { + return; + } setDb({ name: database, connection, diff --git a/packages/web/src/widgets/WidgetContainer.js b/packages/web/src/widgets/WidgetContainer.js index ebd20cc7..51ea1f4b 100644 --- a/packages/web/src/widgets/WidgetContainer.js +++ b/packages/web/src/widgets/WidgetContainer.js @@ -6,7 +6,7 @@ import FavoritesWidget from './FavoritesWidget'; import FilesWidget from './FilesWidget'; import PluginsWidget from './PluginsWidget'; -export default function WidgetContainer() { +function WidgetContainerCore() { const currentWidget = useCurrentWidget(); if (currentWidget === 'database') return ; if (currentWidget === 'file') return ; @@ -15,3 +15,7 @@ export default function WidgetContainer() { if (currentWidget === 'favorites') return ; return null; } + +const WidgetContainer = React.memo(WidgetContainerCore); + +export default WidgetContainer;