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

perf: avoids to create on every request a new object of args #1710

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
12 changes: 6 additions & 6 deletions packages/cli/src/routeGeneration/templates/express.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ export function RegisterRoutes(app: Router) {

{{#each controllers}}
{{#each actions}}
const args{{../name}}_{{name}}: Record<string, TsoaRoute.ParameterSchema> = {
{{#each parameters}}
{{@key}}: {{{json this}}},
{{/each}}
};
app.{{method}}('{{fullPath}}',
{{#if security.length}}
authenticateMiddleware({{json security}}),
Expand All @@ -101,17 +106,12 @@ export function RegisterRoutes(app: Router) {
...(fetchMiddlewares<RequestHandler>({{../name}}.prototype.{{name}})),

async function {{../name}}_{{name}}(request: ExRequest, response: ExResponse, next: any) {
const args: Record<string, TsoaRoute.ParameterSchema> = {
{{#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;
Expand Down
12 changes: 6 additions & 6 deletions packages/cli/src/routeGeneration/templates/hapi.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ export function RegisterRoutes(server: any) {
// ###########################################################################################################
{{#each controllers}}
{{#each actions}}
const args{{../name}}_{{name}}: Record<string, TsoaRoute.ParameterSchema> = {
{{#each parameters}}
{{@key}}: {{{json this}}},
{{/each}}
};
server.route({
method: '{{method}}',
path: '{{fullPath}}',
Expand Down Expand Up @@ -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<string, TsoaRoute.ParameterSchema> = {
{{#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)) {
Expand Down
12 changes: 6 additions & 6 deletions packages/cli/src/routeGeneration/templates/koa.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ export function RegisterRoutes(router: KoaRouter) {

{{#each controllers}}
{{#each actions}}
const args{{../name}}_{{name}}: Record<string, TsoaRoute.ParameterSchema> = {
{{#each parameters}}
{{@key}}: {{{json this}}},
{{/each}}
};
router.{{method}}('{{fullPath}}',
{{#if security.length}}
authenticateMiddleware({{json security}}),
Expand All @@ -97,15 +102,10 @@ export function RegisterRoutes(router: KoaRouter) {
...(fetchMiddlewares<Middleware>({{../name}}.prototype.{{name}})),

async function {{../name}}_{{name}}(context: Context, next: Next) {
const args: Record<string, TsoaRoute.ParameterSchema> = {
{{#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 });
Expand Down
Loading