From 167c07bd63621d11f7425a816f6b0ab6e95acb88 Mon Sep 17 00:00:00 2001 From: Mehdi Sebih Date: Thu, 21 Nov 2024 18:15:30 +0100 Subject: [PATCH] improve check --- lib/schemas.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/schemas.js b/lib/schemas.js index d2e32b90..3d58e1d4 100644 --- a/lib/schemas.js +++ b/lib/schemas.js @@ -1,5 +1,6 @@ 'use strict'; +const schemaVersionsLoaded = {}; var schemas = {}; var schemasByVersion = {}; var dir = require('node-dir'); @@ -8,7 +9,6 @@ var _ = require('lodash'); var baseDir = path.join(path.dirname(module.filename), '../src/main/resources/schema/ans'); -var callback = undefined; var loaded = false; @@ -19,7 +19,7 @@ var loadSchema = function loadSchema(version, done) { return; } - if (_.isObject(schemasByVersion[version])) { + if (schemasByVersion[version] && schemaVersionsLoaded[version]) { done(null, schemasByVersion[version]); return; } @@ -34,6 +34,7 @@ var loadSchema = function loadSchema(version, done) { if (err) throw err; if (!schemasByVersion[version]) { schemasByVersion[version] = {}; + schemaVersionsLoaded[version] = false; } var name = path.relative(schemaDir, filename); try { @@ -52,7 +53,7 @@ var loadSchema = function loadSchema(version, done) { return; } } - loaded = true; + schemaVersionsLoaded[version] = true; if (typeof done == 'function') { done(null, schemasByVersion[version]); return;