Improving the performance of the public configs endpoint on the worker, it was doing a lot of work in sync that could be done in parallel.

This commit is contained in:
mike12345567 2025-04-02 18:00:59 +01:00
parent ebab787e01
commit 4644591326
1 changed files with 41 additions and 19 deletions

View File

@ -1,6 +1,6 @@
import * as email from "../../../utilities/email" import * as email from "../../../utilities/email"
import env from "../../../environment" import env from "../../../environment"
import { googleCallbackUrl, oidcCallbackUrl } from "./auth" import * as auth from "./auth"
import { import {
cache, cache,
configs, configs,
@ -420,13 +420,17 @@ export async function publicSettings(
) { ) {
try { try {
// settings // settings
const configDoc = await configs.getSettingsConfigDoc() const [configDoc, googleConfig] = await Promise.all([
configs.getSettingsConfigDoc(),
configs.getGoogleConfig(),
])
const config = configDoc.config const config = configDoc.config
const branding = await pro.branding.getBrandingConfig(config) const brandingPromise = pro.branding.getBrandingConfig(config)
// enrich the logo url - empty url means deleted // enrich the logo url - empty url means deleted
if (config.logoUrl && config.logoUrl !== "") { if (config.logoUrl && config.logoUrl !== "") {
// pre-signed URLs are promises, but evaluate locally with nominal performance
config.logoUrl = await objectStore.getGlobalFileUrl( config.logoUrl = await objectStore.getGlobalFileUrl(
"settings", "settings",
"logoUrl", "logoUrl",
@ -434,6 +438,37 @@ export async function publicSettings(
) )
} }
// google
const googleDatasourcePromise = configs.getGoogleDatasourceConfig()
const preActivated = googleConfig && googleConfig.activated == null
const google = preActivated || !!googleConfig?.activated
const googleCallbackUrlPromise = auth.googleCallbackUrl(googleConfig)
// oidc
const oidcConfigPromise = configs.getOIDCConfig()
const oidcCallbackUrlPromise = auth.oidcCallbackUrl()
// sso enforced
const isSSOEnforcedPromise = pro.features.isSSOEnforced({ config })
// performance all async work at same time, there is no need for all of these
// operations to occur in sync, slowing the endpoint down significantly
const [
branding,
googleDatasource,
googleCallbackUrl,
oidcConfig,
oidcCallbackUrl,
isSSOEnforced,
] = await Promise.all([
brandingPromise,
googleDatasourcePromise,
googleCallbackUrlPromise,
oidcConfigPromise,
oidcCallbackUrlPromise,
isSSOEnforcedPromise,
])
// enrich the favicon url - empty url means deleted // enrich the favicon url - empty url means deleted
const faviconUrl = const faviconUrl =
branding.faviconUrl && branding.faviconUrl !== "" branding.faviconUrl && branding.faviconUrl !== ""
@ -444,21 +479,8 @@ export async function publicSettings(
) )
: undefined : undefined
// google
const googleConfig = await configs.getGoogleConfig()
const googleDatasourceConfigured =
!!(await configs.getGoogleDatasourceConfig())
const preActivated = googleConfig && googleConfig.activated == null
const google = preActivated || !!googleConfig?.activated
const _googleCallbackUrl = await googleCallbackUrl(googleConfig)
// oidc
const oidcConfig = await configs.getOIDCConfig()
const oidc = oidcConfig?.activated || false const oidc = oidcConfig?.activated || false
const _oidcCallbackUrl = await oidcCallbackUrl() const googleDatasourceConfigured = !!googleDatasource
// sso enforced
const isSSOEnforced = await pro.features.isSSOEnforced({ config })
ctx.body = { ctx.body = {
type: ConfigType.SETTINGS, type: ConfigType.SETTINGS,
@ -472,8 +494,8 @@ export async function publicSettings(
googleDatasourceConfigured, googleDatasourceConfigured,
oidc, oidc,
isSSOEnforced, isSSOEnforced,
oidcCallbackUrl: _oidcCallbackUrl, oidcCallbackUrl,
googleCallbackUrl: _googleCallbackUrl, googleCallbackUrl,
}, },
} }
} catch (err: any) { } catch (err: any) {