Skip to content

Commit 4fb5d24

Browse files
committed
Fix race when fetching schema frequently
1 parent 432c6bf commit 4fb5d24

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

spec/ParseQuery.spec.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1631,8 +1631,9 @@ describe('Parse.Query testing', () => {
16311631
});
16321632
expect(total).toBe(0);
16331633
done()
1634-
}, () => {
1634+
}, (e) => {
16351635
fail('should not fail');
1636+
fail(JSON.stringify(e));
16361637
done();
16371638
})
16381639
});

spec/ParseRelation.spec.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,9 @@ describe('Parse.Relation testing', () => {
575575
expect(result.get('key').get('even')).toBe(false);
576576
});
577577
done();
578+
}, (e) => {
579+
fail(JSON.stringify(e));
580+
done();
578581
})
579582
});
580583

@@ -613,6 +616,9 @@ describe('Parse.Relation testing', () => {
613616
done();
614617
}
615618
}));
619+
}, (e) => {
620+
fail(JSON.stringify(e));
621+
done();
616622
});
617623
});
618624

@@ -653,6 +659,9 @@ describe('Parse.Relation testing', () => {
653659
done();
654660
}
655661
}));
662+
}, (e) => {
663+
fail(JSON.stringify(e));
664+
done();
656665
});
657666
});
658667

src/Controllers/SchemaController.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -333,25 +333,29 @@ export default class SchemaController {
333333
if (this.reloadDataPromise && !options.clearCache) {
334334
return this.reloadDataPromise;
335335
}
336-
this.data = {};
337-
this.perms = {};
338336
this.reloadDataPromise = promise.then(() => {
339337
return this.getAllClasses(options);
340338
})
341339
.then(allSchemas => {
340+
const data = {};
341+
const perms = {};
342342
allSchemas.forEach(schema => {
343-
this.data[schema.className] = injectDefaultSchema(schema).fields;
344-
this.perms[schema.className] = schema.classLevelPermissions;
343+
data[schema.className] = injectDefaultSchema(schema).fields;
344+
perms[schema.className] = schema.classLevelPermissions;
345345
});
346346

347347
// Inject the in-memory classes
348348
volatileClasses.forEach(className => {
349349
const schema = injectDefaultSchema({ className });
350-
this.data[className] = schema.fields;
351-
this.perms[className] = schema.classLevelPermissions;
350+
data[className] = schema.fields;
351+
perms[className] = schema.classLevelPermissions;
352352
});
353+
this.data = data;
354+
this.perms = perms;
353355
delete this.reloadDataPromise;
354356
}, (err) => {
357+
this.data = {};
358+
this.perms = {};
355359
delete this.reloadDataPromise;
356360
throw err;
357361
});

0 commit comments

Comments
 (0)