Skip to content

Commit eb59295

Browse files
committed
Imrpove concurrency of loadSchema
1 parent 0a6eaf3 commit eb59295

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/Controllers/SchemaController.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,12 +283,15 @@ class SchemaController {
283283
}
284284

285285
reloadData(options = {clearCache: false}) {
286-
this.data = {};
287-
this.perms = {};
288286
if (options.clearCache) {
289287
this._cache.clear();
290288
}
291-
return this.getAllClasses(options)
289+
if (this.reloadDataPromise && !options.clearCache) {
290+
return this.reloadDataPromise;
291+
}
292+
this.data = {};
293+
this.perms = {};
294+
this.reloadDataPromise = this.getAllClasses(options)
292295
.then(allSchemas => {
293296
allSchemas.forEach(schema => {
294297
this.data[schema.className] = injectDefaultSchema(schema).fields;
@@ -303,7 +306,12 @@ class SchemaController {
303306
classLevelPermissions: {}
304307
});
305308
});
309+
delete this.reloadDataPromise;
310+
}, (err) => {
311+
delete this.reloadDataPromise;
312+
throw err;
306313
});
314+
return this.reloadDataPromise;
307315
}
308316

309317
getAllClasses(options = {clearCache: false}) {

0 commit comments

Comments
 (0)