From 18fd7e19b5c454e1c8a99fc1f4cf2166c6cf9cfb Mon Sep 17 00:00:00 2001 From: francesco Date: Wed, 30 Oct 2024 14:46:28 +0100 Subject: [PATCH 1/3] perf: avoids to create every request a new object --- .../cli/src/routeGeneration/templates/express.hbs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/cli/src/routeGeneration/templates/express.hbs b/packages/cli/src/routeGeneration/templates/express.hbs index ad1e48c67..0c04797f9 100644 --- a/packages/cli/src/routeGeneration/templates/express.hbs +++ b/packages/cli/src/routeGeneration/templates/express.hbs @@ -81,6 +81,11 @@ export function RegisterRoutes(app: Router) { {{#each controllers}} {{#each actions}} + const args{{../name}}_{{name}}: Record = { + {{#each parameters}} + {{@key}}: {{{json this}}}, + {{/each}} + }; app.{{method}}('{{fullPath}}', {{#if security.length}} authenticateMiddleware({{json security}}), @@ -101,17 +106,12 @@ export function RegisterRoutes(app: Router) { ...(fetchMiddlewares({{../name}}.prototype.{{name}})), async function {{../name}}_{{name}}(request: ExRequest, response: ExResponse, next: any) { - const args: Record = { - {{#each parameters}} - {{@key}}: {{{json this}}}, - {{/each}} - }; // WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa let validatedArgs: any[] = []; try { - validatedArgs = templateService.getValidatedArgs({ args, request, response }); + validatedArgs = templateService.getValidatedArgs({ args: args{{../name}}_{{name}}, request, response }); {{#if ../../iocModule}} const container: IocContainer = typeof iocContainer === 'function' ? (iocContainer as IocContainerFactory)(request) : iocContainer; From 1d8378cdec636cbc198fc89119cd547ec5dcff4e Mon Sep 17 00:00:00 2001 From: francesco Date: Wed, 30 Oct 2024 14:46:45 +0100 Subject: [PATCH 2/3] perf: avoids to create every request a new object --- packages/cli/src/routeGeneration/templates/hapi.hbs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/cli/src/routeGeneration/templates/hapi.hbs b/packages/cli/src/routeGeneration/templates/hapi.hbs index 06b568397..86f2a2668 100644 --- a/packages/cli/src/routeGeneration/templates/hapi.hbs +++ b/packages/cli/src/routeGeneration/templates/hapi.hbs @@ -59,6 +59,11 @@ export function RegisterRoutes(server: any) { // ########################################################################################################### {{#each controllers}} {{#each actions}} + const args{{../name}}_{{name}}: Record = { + {{#each parameters}} + {{@key}}: {{{json this}}}, + {{/each}} + }; server.route({ method: '{{method}}', path: '{{fullPath}}', @@ -92,15 +97,10 @@ export function RegisterRoutes(server: any) { }, {{/if}} handler: {{#if ../../iocModule}}async {{/if}}function {{../name}}_{{name}}(request: Request, h: ResponseToolkit) { - const args: Record = { - {{#each parameters}} - {{@key}}: {{{json this}}}, - {{/each}} - }; let validatedArgs: any[] = []; try { - validatedArgs = templateService.getValidatedArgs({ args, request, h }); + validatedArgs = templateService.getValidatedArgs({ args: args{{../name}}_{{name}}, request, h }); } catch (err) { const error = err as any; if (isBoom(error)) { From 67f85eef6ff5b3ae1315186cfaccf20338025f80 Mon Sep 17 00:00:00 2001 From: francesco Date: Wed, 30 Oct 2024 14:47:03 +0100 Subject: [PATCH 3/3] perf: avoids to create every request a new object --- packages/cli/src/routeGeneration/templates/koa.hbs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/cli/src/routeGeneration/templates/koa.hbs b/packages/cli/src/routeGeneration/templates/koa.hbs index e15cab07d..b0039cf60 100644 --- a/packages/cli/src/routeGeneration/templates/koa.hbs +++ b/packages/cli/src/routeGeneration/templates/koa.hbs @@ -77,6 +77,11 @@ export function RegisterRoutes(router: KoaRouter) { {{#each controllers}} {{#each actions}} + const args{{../name}}_{{name}}: Record = { + {{#each parameters}} + {{@key}}: {{{json this}}}, + {{/each}} + }; router.{{method}}('{{fullPath}}', {{#if security.length}} authenticateMiddleware({{json security}}), @@ -97,15 +102,10 @@ export function RegisterRoutes(router: KoaRouter) { ...(fetchMiddlewares({{../name}}.prototype.{{name}})), async function {{../name}}_{{name}}(context: Context, next: Next) { - const args: Record = { - {{#each parameters}} - {{@key}}: {{{json this}}}, - {{/each}} - }; let validatedArgs: any[] = []; try { - validatedArgs = templateService.getValidatedArgs({ args, context, next }); + validatedArgs = templateService.getValidatedArgs({ args: args{{../name}}_{{name}}, context, next }); } catch (err) { const error = err as any; error.message ||= JSON.stringify({ fields: error.fields });