Closed
Description
New Issue Checklist
- I am not disclosing a vulnerability.
- I am not just asking a question.
- I have searched through existing issues.
- I can reproduce the issue with the latest version of Parse Server.
Issue Description
According to the LiveQuery protocol, the fields parameter can be passed to only listen to updates on certain fields. However, this functions more like "select", where the payload only includes those keys, even if they haven't been updated.
Suppose the ParseObject Player contains three fields name, id and age. If you are only interested in the change of the name field, you can set query.fields to [name]
Steps to reproduce
Create a subscription using the fields parameter, update any other key.
Actual Outcome
Live query is triggered
Expected Outcome
Live query should only trigger if the fields are updated (or new).
Here is an example of a failing test. No matter how many times an object save is called, the spy should only be called if the fields are selected.
it('can handle live query with fields', async () => {
await reconfigureServer({
liveQuery: {
classNames: ['Test'],
},
startLiveQueryServer: true,
});
const query = new Parse.Query('Test');
query.select('yolo');
const subscription = await query.subscribe();
const spy = {
create(obj) {
if (!obj.get('yolo')) {
fail('create should not have been called')
}
},
update(object, original) {
if (object.get('yolo') === original.get('yolo')) {
fail('create should not have been called')
}
}
}
const createSpy = spyOn(spy, 'create').and.callThrough()
const updateSpy = spyOn(spy, 'update').and.callThrough()
subscription.on('create', spy.create);
subscription.on('update', spy.update);
const obj = new Parse.Object('Test');
obj.set('foo', 'bar');
await obj.save();
obj.set('foo', 'xyz');
obj.set('yolo', 'xyz');
await obj.save();
const obj2 = new Parse.Object('Test');
obj2.set('foo', 'bar');
obj2.set('yolo', 'bar');
await obj2.save();
obj2.set('foo','bart');
await obj2.save();
await new Promise(resolve => setTimeout(resolve, 2000));
expect(createSpy).toHaveBeenCalledTimes(1);
expect(updateSpy).toHaveBeenCalledTimes(1);
})
Environment
Server
- Parse Server version:
5.3
- Operating system:
macos
- Local or remote host (AWS, Azure, Google Cloud, Heroku, Digital Ocean, etc):
local
Database
- System (MongoDB or Postgres):
mongo
- Database version:
5.1
- Local or remote host (MongoDB Atlas, mLab, AWS, Azure, Google Cloud, etc):
local
Client
- SDK (iOS, Android, JavaScript, PHP, Unity, etc):
JS
- SDK version:
alpha