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
Add the fields that triggered update notifications #1364
Add the fields that triggered update notifications #1364
Conversation
Codecov Report
@@ Coverage Diff @@
## 1-dev #1364 +/- ##
==========================================
+ Coverage 93.89% 93.89% +<.01%
==========================================
Files 106 106
Lines 7304 7306 +2
==========================================
+ Hits 6858 6860 +2
Misses 446 446
Continue to review full report at Codecov.
|
@@ -65,7 +65,8 @@ describe('Test: notifier.notifyDocumentUpdate', () => { | |||
{ | |||
_id, | |||
_meta: {canIhas: 'cheezburgers?'}, | |||
_source: {foo: 'bar'} | |||
_source: {foo: 'bar'}, | |||
_updatedField: '_kuzzle_info' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't understand the test well I think, for me the field foo
should be present in the _updatedField
array no?
And here _updatedField
is not an array
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is the request sent in this test :
request = new Request({
controller: 'document',
action: 'update',
index: 'foo',
collection: 'bar',
_id: 'Sir Isaac Newton is the deadliest son-of-a-bitch in space',
body: {
_kuzzle_info: {
'canIhas': 'cheezburgers?'
},
foo: 'bar'
}
});
The updated field is _kuzzle_info
as you can see
In deed it's not an array, why should it be ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_source
is the document, in the request it's updated by adding the field _kuzzle_info
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You cannot update the field _kuzzle_info
, it's ignored by the Elasticsearch service.
I mean an array because an update request may modify several fields
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right for the array
for the _kuzzle_info
field :
Since Kuzzle update _kuzzle_info
automatically, do I remove it from the resulted array or not ?
['foo', '_kuzzle_info']
or
['foo']
(for now, i removed it, let me know if its more relevant to keep it)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The updatedFields
gives the following information: "the list of changed fields that triggered that real-time notification`.
_kuzzle_info
is merely a side-effect, always updated alongside any update request, so it cannot be the cause of a real-time notification.
Ergo, _kuzzle_info
should never appear in the updatedFIelds
list.
…ld-updated-in-notification
Co-Authored-By: Sébastien Cottinet <scottinet@protonmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should try with a document containing more than one field. I'm not sure but I think your code just return all document fields except _kuzzle_info
😅 And you should also update the functional tests with a updated fields check 😉
EDIT: I tested with a multiple fields document and it works. But you really should update functional tests to avoid regression.
} else { | ||
console.log('Wrong notification received: '); | ||
console.dir(this.api.responses, { colors: true, depth: null }); | ||
callback('The document was supposed to contain the member "' + member + '" with ' + n_elements + ' elements : Has '+ this.api.responses.result[member].length +'.'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(nitpicking) use string litterals
## What does this PR do ? See the PR title https://jira.kaliop.net/browse/KZL-1127 ### How should this be manually tested? Execute this script and see the notification: ``` const { Kuzzle, WebSocket } = require('kuzzle-sdk'); const kuzzle = new Kuzzle( new WebSocket('localhost') ); function callback (notification) { console.log(notification); } kuzzle.on('networkError', error => { console.error('Network Error:', error); }); const run = async () => { try { await kuzzle.connect(); await kuzzle.document.createOrReplace( 'nyc-open-data', 'yellow-taxi', 'some-id', { capacity: 4, members: 5 }, ); const filters = { exists: 'capacity' }; await kuzzle.realtime.subscribe('nyc-open-data', 'yellow-taxi', filters, callback); const response = await kuzzle.document.update( 'nyc-open-data', 'yellow-taxi', 'some-id', { capacity: 100, members: 50 } ); console.log(response); } catch (error) { console.error(error.message); } finally { kuzzle.disconnect(); } }; run(); ```
What does this PR do ?
See the PR title
https://jira.kaliop.net/browse/KZL-1127
How should this be manually tested?
Execute this script and see the notification: