-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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
Batching Oplog Entries & DDP messages #10478
Closed
Closed
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
a1dd8f6
re-apply: Implemented support for batched DDP messages
KoenLav a1b926e
re-apply: Implemented buffering in Session
KoenLav 2870711
re-apply: Implemented buffering of oplogEntries in Crossbar
KoenLav eac7f03
re-apply: Removed unused code (was intended for larger refactor)
KoenLav 9b8e312
Merge branch 'devel' into re-apply-ddp-rework
filipenevola 6df2b4d
Merge branch 'devel' into re-apply-ddp-rework
filipenevola 7d135e5
Merge branch 'devel' into re-apply-ddp-rework
filipenevola 441515e
Merge branch 'devel' into re-apply-ddp-rework
StorytellerCZ a6640a6
Merge branch 'devel' into re-apply-ddp-rework
StorytellerCZ 100a72c
Merge branch 'devel' into re-apply-ddp-rework
StorytellerCZ 8ac78b3
Merge branch 'devel' into re-apply-ddp-rework
StorytellerCZ 205e554
Merge branch 'devel' into re-apply-ddp-rework
StorytellerCZ 3a16b76
Merge branch 'devel' into re-apply-ddp-rework
StorytellerCZ d425768
Merge branch 'devel' of github.com:meteor/meteor into re-apply-ddp-re…
KoenLav 4a26180
Attempt at 'fixing' (more like evading) tests
KoenLav f0752f1
Merge branch 'devel' into re-apply-ddp-rework
StorytellerCZ 54537a3
Merge branch 'devel' into re-apply-ddp-rework
StorytellerCZ File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,80 +38,118 @@ export function last(array, n, guard) { | |
return slice.call(array, Math.max(array.length - n, 0)); | ||
} | ||
|
||
DDPCommon.ALLOW_BUFFERING = false; | ||
|
||
DDPCommon.SUPPORTED_DDP_VERSIONS = [ '1', 'pre2', 'pre1' ]; | ||
|
||
DDPCommon.parseDDP = function (stringMessage) { | ||
try { | ||
var msg = JSON.parse(stringMessage); | ||
var messages = JSON.parse(stringMessage); | ||
} catch (e) { | ||
Meteor._debug("Discarding message with invalid JSON", stringMessage); | ||
return null; | ||
} | ||
// DDP messages must be objects. | ||
if (msg === null || typeof msg !== 'object') { | ||
Meteor._debug("Discarding non-object DDP message", stringMessage); | ||
Meteor._debug("Discarding message(s) with invalid JSON", stringMessage); | ||
return null; | ||
} | ||
|
||
// Convert all DDP messages to Array form | ||
messages = Array.isArray(messages) ? messages : [messages]; | ||
|
||
for (let i = 0; i < messages.length; i++) { | ||
var msg = messages[i]; | ||
|
||
// massage msg to get it into "abstract ddp" rather than "wire ddp" format. | ||
// Each individual DDP message must be an object. | ||
if (msg === null || typeof msg !== 'object') { | ||
Meteor._debug("Discarding non-object DDP message", stringMessage); | ||
|
||
messages.splice(i, 1); | ||
|
||
// switch between "cleared" rep of unsetting fields and "undefined" | ||
// rep of same | ||
if (hasOwn.call(msg, 'cleared')) { | ||
if (! hasOwn.call(msg, 'fields')) { | ||
msg.fields = {}; | ||
i--; | ||
|
||
continue; | ||
} | ||
msg.cleared.forEach(clearKey => { | ||
msg.fields[clearKey] = undefined; | ||
|
||
// massage msg to get it into "abstract ddp" rather than "wire ddp" format. | ||
|
||
// switch between "cleared" rep of unsetting fields and "undefined" | ||
// rep of same | ||
if (hasOwn.call(msg, 'cleared')) { | ||
if (! hasOwn.call(msg, 'fields')) { | ||
msg.fields = {}; | ||
} | ||
msg.cleared.forEach(clearKey => { | ||
msg.fields[clearKey] = undefined; | ||
}); | ||
delete msg.cleared; | ||
} | ||
|
||
['fields', 'params', 'result'].forEach(field => { | ||
if (hasOwn.call(msg, field)) { | ||
msg[field] = EJSON._adjustTypesFromJSONValue(msg[field]); | ||
} | ||
}); | ||
delete msg.cleared; | ||
} | ||
|
||
['fields', 'params', 'result'].forEach(field => { | ||
if (hasOwn.call(msg, field)) { | ||
msg[field] = EJSON._adjustTypesFromJSONValue(msg[field]); | ||
} | ||
}); | ||
const messagesLength = messages.length; | ||
|
||
return msg; | ||
if (messagesLength === 0) { | ||
return null; | ||
} else if (messagesLength === 1) { | ||
return messages[0]; | ||
} else { | ||
return messages; | ||
} | ||
}; | ||
|
||
DDPCommon.stringifyDDP = function (msg) { | ||
const copy = EJSON.clone(msg); | ||
DDPCommon.stringifyDDP = function (messages) { | ||
messages = Array.isArray(messages) ? messages : [messages]; | ||
|
||
const clonedMessages = []; | ||
|
||
for (let i = 0; i < messages.length; i++) { | ||
const msg = messages[i]; | ||
const copy = EJSON.clone(msg); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here, no changes after this line. |
||
|
||
// swizzle 'changed' messages from 'fields undefined' rep to 'fields | ||
// and cleared' rep | ||
if (hasOwn.call(msg, 'fields')) { | ||
const cleared = []; | ||
// swizzle 'changed' messages from 'fields undefined' rep to 'fields | ||
// and cleared' rep | ||
if (hasOwn.call(msg, 'fields')) { | ||
const cleared = []; | ||
|
||
Object.keys(msg.fields).forEach(key => { | ||
const value = msg.fields[key]; | ||
Object.keys(msg.fields).forEach(key => { | ||
const value = msg.fields[key]; | ||
|
||
if (typeof value === "undefined") { | ||
cleared.push(key); | ||
delete copy.fields[key]; | ||
if (typeof value === "undefined") { | ||
cleared.push(key); | ||
delete copy.fields[key]; | ||
} | ||
}); | ||
|
||
if (! isEmpty(cleared)) { | ||
copy.cleared = cleared; | ||
} | ||
}); | ||
|
||
if (! isEmpty(cleared)) { | ||
copy.cleared = cleared; | ||
if (isEmpty(copy.fields)) { | ||
delete copy.fields; | ||
} | ||
} | ||
|
||
if (isEmpty(copy.fields)) { | ||
delete copy.fields; | ||
} | ||
} | ||
// adjust types to basic | ||
['fields', 'params', 'result'].forEach(field => { | ||
if (hasOwn.call(copy, field)) { | ||
copy[field] = EJSON._adjustTypesToJSONValue(copy[field]); | ||
} | ||
}); | ||
|
||
// adjust types to basic | ||
['fields', 'params', 'result'].forEach(field => { | ||
if (hasOwn.call(copy, field)) { | ||
copy[field] = EJSON._adjustTypesToJSONValue(copy[field]); | ||
if (msg.id && typeof msg.id !== 'string') { | ||
throw new Error("Message id is not a string"); | ||
} | ||
}); | ||
|
||
if (msg.id && typeof msg.id !== 'string') { | ||
throw new Error("Message id is not a string"); | ||
clonedMessages.push(copy); | ||
} | ||
|
||
return JSON.stringify(copy); | ||
const messagesLength = clonedMessages.length; | ||
|
||
if (messagesLength === 1) { | ||
return JSON.stringify(clonedMessages[0]); | ||
} else { | ||
return JSON.stringify(clonedMessages); | ||
} | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Same here, nothing after this line changed.