Skip to content

Schema Cache Improvement 2 #5616

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

Merged
merged 7 commits into from
May 30, 2019
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
142 changes: 133 additions & 9 deletions spec/RedisCacheAdapter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,20 +175,20 @@ describe_only(() => {

beforeEach(async () => {
await cacheAdapter.clear();
getSpy = spyOn(cacheAdapter, 'get').and.callThrough();
putSpy = spyOn(cacheAdapter, 'put').and.callThrough();
await reconfigureServer({
cacheAdapter,
enableSingleSchemaCache: true,
});
getSpy = spyOn(cacheAdapter, 'get').and.callThrough();
putSpy = spyOn(cacheAdapter, 'put').and.callThrough();
});

it('test new object', async () => {
const object = new TestObject();
object.set('foo', 'bar');
await object.save();
expect(getSpy.calls.count()).toBe(4);
expect(putSpy.calls.count()).toBe(3);
expect(getSpy.calls.count()).toBe(2);
expect(putSpy.calls.count()).toBe(2);
});

it('test new object multiple fields', async () => {
Expand All @@ -200,8 +200,8 @@ describe_only(() => {
booleanField: true,
});
await container.save();
expect(getSpy.calls.count()).toBe(4);
expect(putSpy.calls.count()).toBe(3);
expect(getSpy.calls.count()).toBe(2);
expect(putSpy.calls.count()).toBe(2);
});

it('test update existing fields', async () => {
Expand All @@ -214,7 +214,57 @@ describe_only(() => {

object.set('foo', 'barz');
await object.save();
expect(getSpy.calls.count()).toBe(3);
expect(getSpy.calls.count()).toBe(2);
expect(putSpy.calls.count()).toBe(0);
});

it('test saveAll / destroyAll', async () => {
const object = new TestObject();
await object.save();

getSpy.calls.reset();
putSpy.calls.reset();

const objects = [];
for (let i = 0; i < 10; i++) {
const object = new TestObject();
object.set('number', i);
objects.push(object);
}
await Parse.Object.saveAll(objects);
expect(getSpy.calls.count()).toBe(11);
expect(putSpy.calls.count()).toBe(10);

getSpy.calls.reset();
putSpy.calls.reset();

await Parse.Object.destroyAll(objects);
expect(getSpy.calls.count()).toBe(11);
expect(putSpy.calls.count()).toBe(0);
});

it('test saveAll / destroyAll batch', async () => {
const object = new TestObject();
await object.save();

getSpy.calls.reset();
putSpy.calls.reset();

const objects = [];
for (let i = 0; i < 10; i++) {
const object = new TestObject();
object.set('number', i);
objects.push(object);
}
await Parse.Object.saveAll(objects, { batchSize: 5 });
expect(getSpy.calls.count()).toBe(12);
expect(putSpy.calls.count()).toBe(5);

getSpy.calls.reset();
putSpy.calls.reset();

await Parse.Object.destroyAll(objects, { batchSize: 5 });
expect(getSpy.calls.count()).toBe(12);
expect(putSpy.calls.count()).toBe(0);
});

Expand All @@ -228,7 +278,7 @@ describe_only(() => {

object.set('new', 'barz');
await object.save();
expect(getSpy.calls.count()).toBe(3);
expect(getSpy.calls.count()).toBe(2);
expect(putSpy.calls.count()).toBe(1);
});

Expand All @@ -248,8 +298,43 @@ describe_only(() => {
booleanField: true,
});
await object.save();
expect(getSpy.calls.count()).toBe(2);
expect(putSpy.calls.count()).toBe(1);
});

it('test user', async () => {
const user = new Parse.User();
user.setUsername('testing');
user.setPassword('testing');
await user.signUp();

expect(getSpy.calls.count()).toBe(6);
expect(putSpy.calls.count()).toBe(1);
});

it('test allowClientCreation false', async () => {
const object = new TestObject();
await object.save();
await reconfigureServer({
cacheAdapter,
enableSingleSchemaCache: true,
allowClientClassCreation: false,
});
getSpy.calls.reset();
putSpy.calls.reset();

object.set('foo', 'bar');
await object.save();
expect(getSpy.calls.count()).toBe(3);
expect(putSpy.calls.count()).toBe(1);

getSpy.calls.reset();
putSpy.calls.reset();

const query = new Parse.Query(TestObject);
await query.get(object.id);
expect(getSpy.calls.count()).toBe(3);
expect(putSpy.calls.count()).toBe(0);
});

it('test query', async () => {
Expand All @@ -266,6 +351,45 @@ describe_only(() => {
expect(putSpy.calls.count()).toBe(0);
});

it('test query include', async () => {
const child = new TestObject();
await child.save();

const object = new TestObject();
object.set('child', child);
await object.save();

getSpy.calls.reset();
putSpy.calls.reset();

const query = new Parse.Query(TestObject);
query.include('child');
await query.get(object.id);

expect(getSpy.calls.count()).toBe(4);
expect(putSpy.calls.count()).toBe(0);
});

it('query relation without schema', async () => {
const child = new Parse.Object('ChildObject');
await child.save();

const parent = new Parse.Object('ParentObject');
const relation = parent.relation('child');
relation.add(child);
await parent.save();

getSpy.calls.reset();
putSpy.calls.reset();

const objects = await relation.query().find();
expect(objects.length).toBe(1);
expect(objects[0].id).toBe(child.id);

expect(getSpy.calls.count()).toBe(2);
expect(putSpy.calls.count()).toBe(0);
});

it('test delete object', async () => {
const object = new TestObject();
object.set('foo', 'bar');
Expand All @@ -275,7 +399,7 @@ describe_only(() => {
putSpy.calls.reset();

await object.destroy();
expect(getSpy.calls.count()).toBe(3);
expect(getSpy.calls.count()).toBe(2);
expect(putSpy.calls.count()).toBe(0);
});

Expand Down
39 changes: 17 additions & 22 deletions spec/RestQuery.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,31 +181,26 @@ describe('rest query', () => {
);
});

it('query existent class when disabled client class creation', done => {
it('query existent class when disabled client class creation', async () => {
const customConfig = Object.assign({}, config, {
allowClientClassCreation: false,
});
config.database
.loadSchema()
.then(schema => schema.addClassIfNotExists('ClientClassCreation', {}))
.then(actualSchema => {
expect(actualSchema.className).toEqual('ClientClassCreation');
return rest.find(
customConfig,
auth.nobody(customConfig),
'ClientClassCreation',
{}
);
})
.then(
result => {
expect(result.results.length).toEqual(0);
done();
},
() => {
fail('Should not throw error');
}
);
const schema = await config.database.loadSchema();
const actualSchema = await schema.addClassIfNotExists(
'ClientClassCreation',
{}
);
expect(actualSchema.className).toEqual('ClientClassCreation');

await schema.reloadData({ clearCache: true });
// Should not throw
const result = await rest.find(
customConfig,
auth.nobody(customConfig),
'ClientClassCreation',
{}
);
expect(result.results.length).toEqual(0);
});

it('query with wrongly encoded parameter', done => {
Expand Down
1 change: 1 addition & 0 deletions spec/Schema.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,7 @@ describe('SchemaController', () => {
.then(schema => {
return schema
.addClassIfNotExists('NewClass', {})
.then(() => schema.reloadData({ clearCache: true }))
.then(() => {
schema
.hasClass('NewClass')
Expand Down
37 changes: 16 additions & 21 deletions spec/rest.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,30 +181,25 @@ describe('rest create', () => {
);
});

it('handles create on existent class when disabled client class creation', done => {
it('handles create on existent class when disabled client class creation', async () => {
const customConfig = Object.assign({}, config, {
allowClientClassCreation: false,
});
config.database
.loadSchema()
.then(schema => schema.addClassIfNotExists('ClientClassCreation', {}))
.then(actualSchema => {
expect(actualSchema.className).toEqual('ClientClassCreation');
return rest.create(
customConfig,
auth.nobody(customConfig),
'ClientClassCreation',
{}
);
})
.then(
() => {
done();
},
() => {
fail('Should not throw error');
}
);
const schema = await config.database.loadSchema();
const actualSchema = await schema.addClassIfNotExists(
'ClientClassCreation',
{}
);
expect(actualSchema.className).toEqual('ClientClassCreation');

await schema.reloadData({ clearCache: true });
// Should not throw
await rest.create(
customConfig,
auth.nobody(customConfig),
'ClientClassCreation',
{}
);
});

it('handles user signup', done => {
Expand Down
Loading