Skip to content

Commit

Permalink
fix: schema cache not cleared in some cases (parse-community#7771)
Browse files Browse the repository at this point in the history
  • Loading branch information
mtrezza committed Jan 13, 2022
1 parent 66347dc commit 3b92fa1
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 1 deletion.
87 changes: 87 additions & 0 deletions spec/schemas.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const dd = require('deep-diff');
const Config = require('../lib/Config');
const request = require('../lib/request');
const TestUtils = require('../lib/TestUtils');
const SchemaController = require('../lib/Controllers/SchemaController').SchemaController;

let config;

Expand Down Expand Up @@ -239,6 +240,52 @@ describe('schemas', () => {
});
});

it('ensure refresh cache after creating a class', async done => {
spyOn(SchemaController.prototype, 'reloadData').and.callFake(() => Promise.resolve());
await request({
url: 'http://localhost:8378/1/schemas',
method: 'POST',
headers: masterKeyHeaders,
json: true,
body: {
className: 'A',
},
});
const response = await request({
url: 'http://localhost:8378/1/schemas',
method: 'GET',
headers: masterKeyHeaders,
json: true,
});
const expected = {
results: [
userSchema,
roleSchema,
{
className: 'A',
fields: {
//Default fields
ACL: { type: 'ACL' },
createdAt: { type: 'Date' },
updatedAt: { type: 'Date' },
objectId: { type: 'String' },
},
classLevelPermissions: defaultClassLevelPermissions,
},
],
};
expect(
response.data.results
.sort((s1, s2) => s1.className.localeCompare(s2.className))
.map(s => {
const withoutIndexes = Object.assign({}, s);
delete withoutIndexes.indexes;
return withoutIndexes;
})
).toEqual(expected.results.sort((s1, s2) => s1.className.localeCompare(s2.className)));
done();
});

it('responds with a single schema', done => {
const obj = hasAllPODobject();
obj.save().then(() => {
Expand Down Expand Up @@ -1507,6 +1554,46 @@ describe('schemas', () => {
});
});

it('ensure refresh cache after deleting a class', async done => {
config = Config.get('test');
spyOn(config.schemaCache, 'del').and.callFake(() => {});
spyOn(SchemaController.prototype, 'reloadData').and.callFake(() => Promise.resolve());
await request({
url: 'http://localhost:8378/1/schemas',
method: 'POST',
headers: masterKeyHeaders,
json: true,
body: {
className: 'A',
},
});
await request({
method: 'DELETE',
url: 'http://localhost:8378/1/schemas/A',
headers: masterKeyHeaders,
json: true,
});
const response = await request({
url: 'http://localhost:8378/1/schemas',
method: 'GET',
headers: masterKeyHeaders,
json: true,
});
const expected = {
results: [userSchema, roleSchema],
};
expect(
response.data.results
.sort((s1, s2) => s1.className.localeCompare(s2.className))
.map(s => {
const withoutIndexes = Object.assign({}, s);
delete withoutIndexes.indexes;
return withoutIndexes;
})
).toEqual(expected.results.sort((s1, s2) => s1.className.localeCompare(s2.className)));
done();
});

it('deletes collections including join tables', done => {
const obj = new Parse.Object('MyClass');
obj.set('data', 'data');
Expand Down
2 changes: 1 addition & 1 deletion src/Routers/SchemasRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function classNameMismatchResponse(bodyClass, pathClass) {
function getAllSchemas(req) {
return req.config.database
.loadSchema({ clearCache: true })
.then(schemaController => schemaController.getAllClasses(true))
.then(schemaController => schemaController.getAllClasses({ clearCache: true }))
.then(schemas => ({ response: { results: schemas } }));
}

Expand Down

0 comments on commit 3b92fa1

Please sign in to comment.