Skip to content

Commit

Permalink
[8.x] [Rendering] Parallelize ES requests (#199124) (#199171)
Browse files Browse the repository at this point in the history
# Backport

This will backport the following commits from `main` to `8.x`:
- [[Rendering] Parallelize ES requests
(#199124)](#199124)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Alejandro Fernández
Haro","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-11-06T16:09:41Z","message":"[Rendering]
Parallelize ES requests
(#199124)","sha":"be3c159cfc9915abc48a409e123ee11070d34dba","branchLabelMapping":{"^v9.0.0$":"main","^v8.17.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Team:Core","performance","release_note:skip","v9.0.0","backport:prev-minor","Team:Performance"],"title":"[Rendering]
Parallelize ES
requests","number":199124,"url":"https://github.com/elastic/kibana/pull/199124","mergeCommit":{"message":"[Rendering]
Parallelize ES requests
(#199124)","sha":"be3c159cfc9915abc48a409e123ee11070d34dba"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/199124","number":199124,"mergeCommit":{"message":"[Rendering]
Parallelize ES requests
(#199124)","sha":"be3c159cfc9915abc48a409e123ee11070d34dba"}}]}]
BACKPORT-->

Co-authored-by: Alejandro Fernández Haro <[email protected]>
  • Loading branch information
kibanamachine and afharo authored Nov 6, 2024
1 parent 4e53ca9 commit d040cc4
Showing 1 changed file with 24 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -148,23 +148,29 @@ export class RenderingService {
const basePath = http.basePath.get(request);
const { serverBasePath, publicBaseUrl } = http.basePath;

let settingsUserValues: Record<string, UserProvidedValues> = {};
let globalSettingsUserValues: Record<string, UserProvidedValues> = {};

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<Record<string, UserProvidedValues>>,
Promise<Record<string, UserProvidedValues>>,
Promise<DarkModeValue> | undefined
])
: []),
]);

const settings = {
defaults: defaultSettings,
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit d040cc4

Please sign in to comment.