Skip to content

Commit

Permalink
#202: debug logs
Browse files Browse the repository at this point in the history
  • Loading branch information
mohit-s96 committed Nov 21, 2024
1 parent 6626e4c commit e9c3a37
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/schema/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const IGNORE_ENUMS = 'ignoreEnumerations';
const createHeapUsageLogger = (interval = 0) => {
let peak = -1;
if (interval === 0) {
process.on('exit', () => console.log('Peak heap usage: ' + (peak / 1024 / 1024).toFixed(2)));
process.on('exit', () => console.log('Peak heap usage: ' + (peak / 1024 / 1024).toFixed(2) + 'MB'));
}
return () => {
setInterval(
Expand Down
20 changes: 19 additions & 1 deletion lib/schema/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,14 @@ const {
SCHEMA_ERROR_KEYWORDS,
getKeyFieldForResource,
getValueForKeyField,
chunkPayload
chunkPayload,
createHeapUsageLogger
} = require('./utils');
const { validationContext } = require('./context');

// TODO: remove
createHeapUsageLogger()();

/**
* @typedef {import('ajv').ValidateFunction} ValidateFunction
*/
Expand Down Expand Up @@ -165,11 +169,20 @@ const validate = ({
cachedSchema = { ...schema };
schemaCache.set(schemaId, cachedSchema);
}
console.time('Compile schema');
const validate = ajv.compile(cachedSchema);
console.timeEnd('Compile schema');

console.time('Chunk payload');
const chunked = chunkPayload(payload);
console.timeEnd('Chunk payload');

console.time('Validate with AJV');
const timings = [];
for (const p of chunked) {
const valid = validate(p);
if (!valid) {
const start = Date.now();
generateErrorReport({
validate,
json: p,
Expand All @@ -184,8 +197,13 @@ const validate = ({
isRCF: validationContext.isRCF(),
metadataMap: schema?.definitions?.MetadataMap || {}
});
const stop = Date.now();
timings.push(stop - start);
}
}

console.timeEnd('Validate with AJV');
console.log(`Time spent on generating reports: ${timings.reduce((acc, curr) => acc += curr)}ms`);

schema.oneOf = oldOneOf;
validationContext.reset();
Expand Down

0 comments on commit e9c3a37

Please sign in to comment.