From d040cc4131c66ecde3a5163359a5d98f2ea18045 Mon Sep 17 00:00:00 2001 From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Date: Thu, 7 Nov 2024 04:55:45 +1100 Subject: [PATCH] [8.x] [Rendering] Parallelize ES requests (#199124) (#199171) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Backport This will backport the following commits from `main` to `8.x`: - [[Rendering] Parallelize ES requests (#199124)](https://github.com/elastic/kibana/pull/199124) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) Co-authored-by: Alejandro Fernández Haro --- .../src/rendering_service.tsx | 46 ++++++++++--------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/packages/core/rendering/core-rendering-server-internal/src/rendering_service.tsx b/packages/core/rendering/core-rendering-server-internal/src/rendering_service.tsx index 44841ec0fbe3f..ace0399f242af 100644 --- a/packages/core/rendering/core-rendering-server-internal/src/rendering_service.tsx +++ b/packages/core/rendering/core-rendering-server-internal/src/rendering_service.tsx @@ -20,10 +20,10 @@ import type { IUiSettingsClient } from '@kbn/core-ui-settings-server'; import type { UiPlugins } from '@kbn/core-plugins-base-server-internal'; import type { CustomBranding } from '@kbn/core-custom-branding-common'; import { - type UserProvidedValues, type DarkModeValue, parseDarkModeValue, type UiSettingsParams, + type UserProvidedValues, } from '@kbn/core-ui-settings-common'; import { Template } from './views'; import { @@ -148,23 +148,29 @@ export class RenderingService { const basePath = http.basePath.get(request); const { serverBasePath, publicBaseUrl } = http.basePath; - let settingsUserValues: Record = {}; - let globalSettingsUserValues: Record = {}; - - if (!isAnonymousPage) { - const userValues = await Promise.all([ - uiSettings.client?.getUserProvided(), - uiSettings.globalClient?.getUserProvided(), - ]); - - settingsUserValues = userValues[0]; - globalSettingsUserValues = userValues[1]; - } - - const defaultSettings = await withAsyncDefaultValues( - request, - uiSettings.client?.getRegistered() - ); + // Grouping all async HTTP requests to run them concurrently for performance reasons. + const [ + defaultSettings, + settingsUserValues = {}, + globalSettingsUserValues = {}, + userSettingDarkMode, + ] = await Promise.all([ + // All sites + withAsyncDefaultValues(request, uiSettings.client?.getRegistered()), + // Only non-anonymous pages + ...(!isAnonymousPage + ? ([ + uiSettings.client?.getUserProvided(), + uiSettings.globalClient?.getUserProvided(), + // dark mode + userSettings?.getUserSettingDarkMode(request), + ] as [ + Promise>, + Promise>, + Promise | undefined + ]) + : []), + ]); const settings = { defaults: defaultSettings, @@ -196,10 +202,6 @@ export class RenderingService { } // dark mode - const userSettingDarkMode = isAnonymousPage - ? undefined - : await userSettings?.getUserSettingDarkMode(request); - const isThemeOverridden = settings.user['theme:darkMode']?.isOverridden ?? false; let darkMode: DarkModeValue;