Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.x] [Rendering] Parallelize ES requests (#199124) #199171

Merged
merged 1 commit into from
Nov 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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