Skip to content

Commit

Permalink
Compile validator only once instead of once per validation
Browse files Browse the repository at this point in the history
This is significantly faster and drops the lambda loading events from timing out after 30 seconds to finishing after 2,5 seconds
  • Loading branch information
dbartholomae committed Nov 13, 2022
1 parent 75424ea commit 924c69a
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion util/validation/src/makeEnsureType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { klona as clone } from "klona";
import { createAjv } from "./ajv";

export function makeEnsureType<Type>(schema: JSONSchema, ajvOptions?: Options) {
const validate = createAjv(ajvOptions).compile(schema);
return function ensure(data: unknown): Type {
const validate = createAjv(ajvOptions).compile(schema);
const clonedData = clone(data);
validate(clonedData);
const { errors } = validate;
Expand Down

0 comments on commit 924c69a

Please sign in to comment.