Skip to content
This repository has been archived by the owner on Nov 8, 2024. It is now read-only.

Commit

Permalink
perf(oas2): cache body asset for $ref's with same content type
Browse files Browse the repository at this point in the history
With some larger API Description documents the parse time goes down from
~80 seconds to ~14 seconds.
  • Loading branch information
kylef committed Feb 7, 2020
1 parent b14bdee commit 600ca9e
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion packages/fury-adapter-swagger/lib/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -1530,7 +1530,16 @@ class Parser {

pushAssets(schema, payload, contentType, pushBody) {
let jsonSchema;

if (this.bodyCache === undefined) {
this.bodyCache = {};
}

const referencedPathValue = this.referencedPathValue();
let cacheKey;
if (referencedPathValue && referencedPathValue.$ref) {
cacheKey = `${referencedPathValue.$ref};${contentType}`;
}

try {
const root = { definitions: this.definitions };
Expand All @@ -1542,7 +1551,15 @@ class Parser {
}

if (pushBody) {
bodyFromSchema(jsonSchema, payload, this, contentType);
if (cacheKey && this.bodyCache[cacheKey]) {
const asset = this.bodyCache[cacheKey];
payload.push(asset.clone());
} else {
const asset = bodyFromSchema(jsonSchema, payload, this, contentType);
if (cacheKey) {
this.bodyCache[cacheKey] = asset;
}
}
}

this.pushSchemaAsset(schema, jsonSchema, payload, this.path);
Expand Down

0 comments on commit 600ca9e

Please # to comment.