Skip to content

Commit 3b92fa1

Browse files
authored
fix: schema cache not cleared in some cases (#7771)
1 parent 66347dc commit 3b92fa1

File tree

2 files changed

+88
-1
lines changed

2 files changed

+88
-1
lines changed

spec/schemas.spec.js

+87
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const dd = require('deep-diff');
55
const Config = require('../lib/Config');
66
const request = require('../lib/request');
77
const TestUtils = require('../lib/TestUtils');
8+
const SchemaController = require('../lib/Controllers/SchemaController').SchemaController;
89

910
let config;
1011

@@ -239,6 +240,52 @@ describe('schemas', () => {
239240
});
240241
});
241242

243+
it('ensure refresh cache after creating a class', async done => {
244+
spyOn(SchemaController.prototype, 'reloadData').and.callFake(() => Promise.resolve());
245+
await request({
246+
url: 'http://localhost:8378/1/schemas',
247+
method: 'POST',
248+
headers: masterKeyHeaders,
249+
json: true,
250+
body: {
251+
className: 'A',
252+
},
253+
});
254+
const response = await request({
255+
url: 'http://localhost:8378/1/schemas',
256+
method: 'GET',
257+
headers: masterKeyHeaders,
258+
json: true,
259+
});
260+
const expected = {
261+
results: [
262+
userSchema,
263+
roleSchema,
264+
{
265+
className: 'A',
266+
fields: {
267+
//Default fields
268+
ACL: { type: 'ACL' },
269+
createdAt: { type: 'Date' },
270+
updatedAt: { type: 'Date' },
271+
objectId: { type: 'String' },
272+
},
273+
classLevelPermissions: defaultClassLevelPermissions,
274+
},
275+
],
276+
};
277+
expect(
278+
response.data.results
279+
.sort((s1, s2) => s1.className.localeCompare(s2.className))
280+
.map(s => {
281+
const withoutIndexes = Object.assign({}, s);
282+
delete withoutIndexes.indexes;
283+
return withoutIndexes;
284+
})
285+
).toEqual(expected.results.sort((s1, s2) => s1.className.localeCompare(s2.className)));
286+
done();
287+
});
288+
242289
it('responds with a single schema', done => {
243290
const obj = hasAllPODobject();
244291
obj.save().then(() => {
@@ -1507,6 +1554,46 @@ describe('schemas', () => {
15071554
});
15081555
});
15091556

1557+
it('ensure refresh cache after deleting a class', async done => {
1558+
config = Config.get('test');
1559+
spyOn(config.schemaCache, 'del').and.callFake(() => {});
1560+
spyOn(SchemaController.prototype, 'reloadData').and.callFake(() => Promise.resolve());
1561+
await request({
1562+
url: 'http://localhost:8378/1/schemas',
1563+
method: 'POST',
1564+
headers: masterKeyHeaders,
1565+
json: true,
1566+
body: {
1567+
className: 'A',
1568+
},
1569+
});
1570+
await request({
1571+
method: 'DELETE',
1572+
url: 'http://localhost:8378/1/schemas/A',
1573+
headers: masterKeyHeaders,
1574+
json: true,
1575+
});
1576+
const response = await request({
1577+
url: 'http://localhost:8378/1/schemas',
1578+
method: 'GET',
1579+
headers: masterKeyHeaders,
1580+
json: true,
1581+
});
1582+
const expected = {
1583+
results: [userSchema, roleSchema],
1584+
};
1585+
expect(
1586+
response.data.results
1587+
.sort((s1, s2) => s1.className.localeCompare(s2.className))
1588+
.map(s => {
1589+
const withoutIndexes = Object.assign({}, s);
1590+
delete withoutIndexes.indexes;
1591+
return withoutIndexes;
1592+
})
1593+
).toEqual(expected.results.sort((s1, s2) => s1.className.localeCompare(s2.className)));
1594+
done();
1595+
});
1596+
15101597
it('deletes collections including join tables', done => {
15111598
const obj = new Parse.Object('MyClass');
15121599
obj.set('data', 'data');

src/Routers/SchemasRouter.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function classNameMismatchResponse(bodyClass, pathClass) {
1616
function getAllSchemas(req) {
1717
return req.config.database
1818
.loadSchema({ clearCache: true })
19-
.then(schemaController => schemaController.getAllClasses(true))
19+
.then(schemaController => schemaController.getAllClasses({ clearCache: true }))
2020
.then(schemas => ({ response: { results: schemas } }));
2121
}
2222

0 commit comments

Comments
 (0)