From 8f6e11959432c5b3e349f07913ef3e37d956b382 Mon Sep 17 00:00:00 2001 From: Ricardo Devis Agullo Date: Wed, 27 May 2026 12:07:33 +0200 Subject: [PATCH] perf(get-component): cache acceptLanguageParser.parse results MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit acceptLanguageParser.parse is called on every data-provider request with the same Accept-Language header value. Since it's a pure function (same input → same output), cache the result using the existing nice-cache instance keyed by the raw header string. This avoids repeated parsing of identical Accept-Language headers across concurrent and sequential requests from the same browser. --- .../oc/src/registry/routes/helpers/get-component.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/oc/src/registry/routes/helpers/get-component.ts b/packages/oc/src/registry/routes/helpers/get-component.ts index e2f73135..c8a9b9a4 100644 --- a/packages/oc/src/registry/routes/helpers/get-component.ts +++ b/packages/oc/src/registry/routes/helpers/get-component.ts @@ -141,6 +141,14 @@ export default function getComponent(conf: Config, repository: Repository) { }); const convertPlugins = pluginConverter(conf.plugins); + const parseAcceptLanguage = (header: string) => { + const cached = cache.get('accept-language', header); + if (cached) return cached; + const parsed = acceptLanguageParser.parse(header); + cache.set('accept-language', header, parsed); + return parsed; + }; + const getEnv = async ( component: Component ): Promise> => { @@ -588,7 +596,9 @@ export default function getComponent(conf: Config, repository: Repository) { emptyResponseHandler.contextDecorator(returnComponent); const contextObj = { action: options.action, - acceptLanguage: acceptLanguageParser.parse(acceptLanguage!), + acceptLanguage: acceptLanguage + ? parseAcceptLanguage(acceptLanguage) + : [], baseUrl: conf.baseUrl, env: { ...conf.env, ...env }, params,