Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: schema cache not cleared in some cases #7678

Merged
merged 5 commits into from
Jan 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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