Skip to content

Commit

Permalink
fix: schema loading performance
Browse files Browse the repository at this point in the history
  • Loading branch information
p-spacek authored and gorkem committed Oct 7, 2023
1 parent 8f508fa commit 02d69fe
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/languageservice/services/yamlSchemaService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ export class YAMLSchemaService extends JSONSchemaService {
}

const toWalk: JSONSchema[] = [node];
const seen: JSONSchema[] = [];
const seen: Set<JSONSchema> = new Set();

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const openPromises: Promise<any>[] = [];
Expand Down Expand Up @@ -278,7 +278,7 @@ export class YAMLSchemaService extends JSONSchemaService {
}
};
const handleRef = (next: JSONSchema): void => {
const seenRefs = [];
const seenRefs = new Set();
while (next.$ref) {
const ref = next.$ref;
const segments = ref.split('#', 2);
Expand All @@ -289,9 +289,9 @@ export class YAMLSchemaService extends JSONSchemaService {
openPromises.push(resolveExternalLink(next, segments[0], segments[1], parentSchemaURL, parentSchemaDependencies));
return;
} else {
if (seenRefs.indexOf(ref) === -1) {
if (!seenRefs.has(ref)) {
merge(next, parentSchema, parentSchemaURL, segments[1]); // can set next.$ref again, use seenRefs to avoid circle
seenRefs.push(ref);
seenRefs.add(ref);
}
}
}
Expand Down Expand Up @@ -330,10 +330,10 @@ export class YAMLSchemaService extends JSONSchemaService {

while (toWalk.length) {
const next = toWalk.pop();
if (seen.indexOf(next) >= 0) {
if (seen.has(next)) {
continue;
}
seen.push(next);
seen.add(next);
handleRef(next);
}
return Promise.all(openPromises);
Expand Down

0 comments on commit 02d69fe

Please sign in to comment.