{"action":"created","comment":{"url":"https://api.github.com/repos/code-dot-org/code-dot-org/pulls/comments/37661170","id":37661170,"diff_hunk":"@@ -92,28 +92,72 @@ var NetSimMessage = module.exports = function (shard, messageRow) {\n NetSimMessage.inherits(NetSimEntity);\n \n /**\n+ * @typedef {Object} MessageData\n+ * @property {!number} fromNodeID - sender node ID\n+ * @property {!number} toNodeID - destination node ID\n+ * @property {!number} simulatedBy - node ID of client simulating message\n+ * @property {*} payload - message content\n+ * @property {number} extraHopsRemaining\n+ * @property {number[]} visitedNodeIDs\n+ */\n+\n+/**\n+ * @typedef {Object} MessageRow\n+ * @property {number} fromNodeID - this message in-flight-from node\n+ * @property {number} toNodeID - this message in-flight-to node\n+ * @property {number} simulatedBy - Node ID of the client responsible for\n+ *           all operations involving this message.\n+ * @property {Base64Payload} base64Payload - base64-encoded binary\n+ *           message content, all of which can be exposed to the\n+ *           student.  May contain headers of its own.\n+ */\n+\n+/**\n+ * Static row construction method. Used by dynamic buildRow method and\n+ * by static async API creation methods to create a properly-formatted\n+ * row for database insertion\n+ * @param {MessageData} messageData\n+ * @returns {MessageRow}\n+ * @throws {TypeError} if payload is invalid\n+ */\n+NetSimMessage.buildRowFromData = function (messageData) {\n+  return {\n+    fromNodeID: messageData.fromNodeID,\n+    toNodeID: messageData.toNodeID,\n+    simulatedBy: messageData.simulatedBy,\n+    base64Payload: binaryToBase64(messageData.payload),\n+    extraHopsRemaining: utils.valueOr(messageData.extraHopsRemaining, 0),\n+    visitedNodeIDs: utils.valueOr(messageData.visitedNodeIDs, [])\n+  };\n+};\n+\n+/**\n  * Static async creation method.  Creates a new message on the given shard,\n  * and then calls the callback with a success boolean.\n  * @param {!NetSimShard} shard\n- * @param {Object} messageData\n- * @param {!number} messageData.fromNodeID - sender node ID\n- * @param {!number} messageData.toNodeID - destination node ID\n- * @param {!number} messageData.simulatedBy - node ID of client simulating message\n- * @param {*} messageData.payload - message content\n- * @param {number} messageData.extraHopsRemaining\n- * @param {number[]} messageData.visitedNodeIDs\n+ * @param {MessageData} messageData\n  * @param {!NodeStyleCallback} onComplete (success)\n  */\n NetSimMessage.send = function (shard, messageData, onComplete) {\n-  var entity = new NetSimMessage(shard);\n-  entity.fromNodeID = messageData.fromNodeID;\n-  entity.toNodeID = messageData.toNodeID;\n-  entity.simulatedBy = messageData.simulatedBy;\n-  entity.payload = messageData.payload;\n-  entity.extraHopsRemaining = utils.valueOr(messageData.extraHopsRemaining, 0);\n-  entity.visitedNodeIDs = utils.valueOr(messageData.visitedNodeIDs, []);\n   try {\n-    entity.getTable().create(entity.buildRow(), onComplete);\n+    var row = NetSimMessage.buildRowFromData(messageData);\n+    shard.messageTable.create(row, onComplete);\n+  } catch (err) {\n+    onComplete(err, null);\n+  }\n+};\n+\n+/**\n+ * Static async multi-create method. Creates new messages on the given shard,\n+ * and then calls the callback with a success boolean.\n+ * @param {!NetSimShard} shard\n+ * @param {MessageData[]} messageDatas\n+ * @param {!NodeStyleCallback} onComplete (success)\n+ */\n+NetSimMessage.sendMany = function (shard, messageDatas, onComplete) {\n+  try {\n+    var rows = messageDatas.map(NetSimMessage.buildRowFromData);\n+    shard.messageTable.create(rows, onComplete);","path":"apps/src/netsim/NetSimMessage.js","position":84,"original_position":84,"commit_id":"3b627d73c79eed7521ffbf5e742fa8c600339eb4","original_commit_id":"3b627d73c79eed7521ffbf5e742fa8c600339eb4","user":{"login":"islemaster","id":1615761,"avatar_url":"https://avatars.githubusercontent.com/u/1615761?v=3","gravatar_id":"","url":"https://api.github.com/users/islemaster","html_url":"https://github.com/islemaster","followers_url":"https://api.github.com/users/islemaster/followers","following_url":"https://api.github.com/users/islemaster/following{/other_user}","gists_url":"https://api.github.com/users/islemaster/gists{/gist_id}","starred_url":"https://api.github.com/users/islemaster/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/islemaster/subscriptions","organizations_url":"https://api.github.com/users/islemaster/orgs","repos_url":"https://api.github.com/users/islemaster/repos","events_url":"https://api.github.com/users/islemaster/events{/privacy}","received_events_url":"https://api.github.com/users/islemaster/received_events","type":"User","site_admin":false},"body":"This does seem to be an issue; `grunt test --grep NetSim` fails a NetSimRouterNode test for me on this branch.","created_at":"2015-08-21T18:07:38Z","updated_at":"2015-08-21T18:07:38Z","html_url":"https://github.com/code-dot-org/code-dot-org/pull/3628#discussion_r37661170","pull_request_url":"https://api.github.com/repos/code-dot-org/code-dot-org/pulls/3628","_links":{"self":{"href":"https://api.github.com/repos/code-dot-org/code-dot-org/pulls/comments/37661170"},"html":{"href":"https://github.com/code-dot-org/code-dot-org/pull/3628#discussion_r37661170"},"pull_request":{"href":"https://api.github.com/repos/code-dot-org/code-dot-org/pulls/3628"}}},"pull_request":{"url":"https://api.github.com/repos/code-dot-org/code-dot-org/pulls/3628","id":42760002,"html_url":"https://github.com/code-dot-org/code-dot-org/pull/3628","diff_url":"https://github.com/code-dot-org/code-dot-org/pull/3628.diff","patch_url":"https://github.com/code-dot-org/code-dot-org/pull/3628.patch","issue_url":"https://api.github.com/repos/code-dot-org/code-dot-org/issues/3628","number":3628,"state":"open","locked":false,"title":"Adds multi-insert to Net Sim","user":{"login":"Hamms","id":244100,"avatar_url":"https://avatars.githubusercontent.com/u/244100?v=3","gravatar_id":"","url":"https://api.github.com/users/Hamms","html_url":"https://github.com/Hamms","followers_url":"https://api.github.com/users/Hamms/followers","following_url":"https://api.github.com/users/Hamms/following{/other_user}","gists_url":"https://api.github.com/users/Hamms/gists{/gist_id}","starred_url":"https://api.github.com/users/Hamms/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Hamms/subscriptions","organizations_url":"https://api.github.com/users/Hamms/orgs","repos_url":"https://api.github.com/users/Hamms/repos","events_url":"https://api.github.com/users/Hamms/events{/privacy}","received_events_url":"https://api.github.com/users/Hamms/received_events","type":"User","site_admin":false},"body":"In Broadcast mode, every message POST results in the router queueing up an additional `N` message POSTs (where `N` = the number of Nodes in the room), which can result in significant clientside lag.\r\n\r\nThis PR refactors those `N` queued message POSTs into a single POST with `N` messages in it. This means that each message sent in Broadcast mode will result in a total of two POSTS rather than `N+1` POSTS.","created_at":"2015-08-18T23:09:45Z","updated_at":"2015-08-21T18:07:38Z","closed_at":null,"merged_at":null,"merge_commit_sha":"1db7d9e42fc8a96260894e00d48872cb7bd5aca4","assignee":{"login":"philbogle","id":5198586,"avatar_url":"https://avatars.githubusercontent.com/u/5198586?v=3","gravatar_id":"","url":"https://api.github.com/users/philbogle","html_url":"https://github.com/philbogle","followers_url":"https://api.github.com/users/philbogle/followers","following_url":"https://api.github.com/users/philbogle/following{/other_user}","gists_url":"https://api.github.com/users/philbogle/gists{/gist_id}","starred_url":"https://api.github.com/users/philbogle/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/philbogle/subscriptions","organizations_url":"https://api.github.com/users/philbogle/orgs","repos_url":"https://api.github.com/users/philbogle/repos","events_url":"https://api.github.com/users/philbogle/events{/privacy}","received_events_url":"https://api.github.com/users/philbogle/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/code-dot-org/code-dot-org/pulls/3628/commits","review_comments_url":"https://api.github.com/repos/code-dot-org/code-dot-org/pulls/3628/comments","review_comment_url":"https://api.github.com/repos/code-dot-org/code-dot-org/pulls/comments{/number}","comments_url":"https://api.github.com/repos/code-dot-org/code-dot-org/issues/3628/comments","statuses_url":"https://api.github.com/repos/code-dot-org/code-dot-org/statuses/3b627d73c79eed7521ffbf5e742fa8c600339eb4","head":{"label":"code-dot-org:netsim-multi-insert","ref":"netsim-multi-insert","sha":"3b627d73c79eed7521ffbf5e742fa8c600339eb4","user":{"login":"code-dot-org","id":5124627,"avatar_url":"https://avatars.githubusercontent.com/u/5124627?v=3","gravatar_id":"","url":"https://api.github.com/users/code-dot-org","html_url":"https://github.com/code-dot-org","followers_url":"https://api.github.com/users/code-dot-org/followers","following_url":"https://api.github.com/users/code-dot-org/following{/other_user}","gists_url":"https://api.github.com/users/code-dot-org/gists{/gist_id}","starred_url":"https://api.github.com/users/code-dot-org/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/code-dot-org/subscriptions","organizations_url":"https://api.github.com/users/code-dot-org/orgs","repos_url":"https://api.github.com/users/code-dot-org/repos","events_url":"https://api.github.com/users/code-dot-org/events{/privacy}","received_events_url":"https://api.github.com/users/code-dot-org/received_events","type":"Organization","site_admin":false},"repo":{"id":24250009,"name":"code-dot-org","full_name":"code-dot-org/code-dot-org","owner":{"login":"code-dot-org","id":5124627,"avatar_url":"https://avatars.githubusercontent.com/u/5124627?v=3","gravatar_id":"","url":"https://api.github.com/users/code-dot-org","html_url":"https://github.com/code-dot-org","followers_url":"https://api.github.com/users/code-dot-org/followers","following_url":"https://api.github.com/users/code-dot-org/following{/other_user}","gists_url":"https://api.github.com/users/code-dot-org/gists{/gist_id}","starred_url":"https://api.github.com/users/code-dot-org/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/code-dot-org/subscriptions","organizations_url":"https://api.github.com/users/code-dot-org/orgs","repos_url":"https://api.github.com/users/code-dot-org/repos","events_url":"https://api.github.com/users/code-dot-org/events{/privacy}","received_events_url":"https://api.github.com/users/code-dot-org/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/code-dot-org/code-dot-org","description":"The code powering code.org and studio.code.org","fork":false,"url":"https://api.github.com/repos/code-dot-org/code-dot-org","forks_url":"https://api.github.com/repos/code-dot-org/code-dot-org/forks","keys_url":"https://api.github.com/repos/code-dot-org/code-dot-org/keys{/key_id}","collaborators_url":"https://api.github.com/repos/code-dot-org/code-dot-org/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/code-dot-org/code-dot-org/teams","hooks_url":"https://api.github.com/repos/code-dot-org/code-dot-org/hooks","issue_events_url":"https://api.github.com/repos/code-dot-org/code-dot-org/issues/events{/number}","events_url":"https://api.github.com/repos/code-dot-org/code-dot-org/events","assignees_url":"https://api.github.com/repos/code-dot-org/code-dot-org/assignees{/user}","branches_url":"https://api.github.com/repos/code-dot-org/code-dot-org/branches{/branch}","tags_url":"https://api.github.com/repos/code-dot-org/code-dot-org/tags","blobs_url":"https://api.github.com/repos/code-dot-org/code-dot-org/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/code-dot-org/code-dot-org/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/code-dot-org/code-dot-org/git/refs{/sha}","trees_url":"https://api.github.com/repos/code-dot-org/code-dot-org/git/trees{/sha}","statuses_url":"https://api.github.com/repos/code-dot-org/code-dot-org/statuses/{sha}","languages_url":"https://api.github.com/repos/code-dot-org/code-dot-org/languages","stargazers_url":"https://api.github.com/repos/code-dot-org/code-dot-org/stargazers","contributors_url":"https://api.github.com/repos/code-dot-org/code-dot-org/contributors","subscribers_url":"https://api.github.com/repos/code-dot-org/code-dot-org/subscribers","subscription_url":"https://api.github.com/repos/code-dot-org/code-dot-org/subscription","commits_url":"https://api.github.com/repos/code-dot-org/code-dot-org/commits{/sha}","git_commits_url":"https://api.github.com/repos/code-dot-org/code-dot-org/git/commits{/sha}","comments_url":"https://api.github.com/repos/code-dot-org/code-dot-org/comments{/number}","issue_comment_url":"https://api.github.com/repos/code-dot-org/code-dot-org/issues/comments{/number}","contents_url":"https://api.github.com/repos/code-dot-org/code-dot-org/contents/{+path}","compare_url":"https://api.github.com/repos/code-dot-org/code-dot-org/compare/{base}...{head}","merges_url":"https://api.github.com/repos/code-dot-org/code-dot-org/merges","archive_url":"https://api.github.com/repos/code-dot-org/code-dot-org/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/code-dot-org/code-dot-org/downloads","issues_url":"https://api.github.com/repos/code-dot-org/code-dot-org/issues{/number}","pulls_url":"https://api.github.com/repos/code-dot-org/code-dot-org/pulls{/number}","milestones_url":"https://api.github.com/repos/code-dot-org/code-dot-org/milestones{/number}","notifications_url":"https://api.github.com/repos/code-dot-org/code-dot-org/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/code-dot-org/code-dot-org/labels{/name}","releases_url":"https://api.github.com/repos/code-dot-org/code-dot-org/releases{/id}","created_at":"2014-09-20T00:46:11Z","updated_at":"2015-08-21T05:47:46Z","pushed_at":"2015-08-21T18:04:14Z","git_url":"git://github.com/code-dot-org/code-dot-org.git","ssh_url":"git@github.com:code-dot-org/code-dot-org.git","clone_url":"https://github.com/code-dot-org/code-dot-org.git","svn_url":"https://github.com/code-dot-org/code-dot-org","homepage":"http://code.org","size":2478660,"stargazers_count":53,"watchers_count":53,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":37,"mirror_url":null,"open_issues_count":33,"forks":37,"open_issues":33,"watchers":53,"default_branch":"staging"}},"base":{"label":"code-dot-org:staging","ref":"staging","sha":"5fcdb5bb3dc7dcd4c4898cc7be5b7ef2a55abed9","user":{"login":"code-dot-org","id":5124627,"avatar_url":"https://avatars.githubusercontent.com/u/5124627?v=3","gravatar_id":"","url":"https://api.github.com/users/code-dot-org","html_url":"https://github.com/code-dot-org","followers_url":"https://api.github.com/users/code-dot-org/followers","following_url":"https://api.github.com/users/code-dot-org/following{/other_user}","gists_url":"https://api.github.com/users/code-dot-org/gists{/gist_id}","starred_url":"https://api.github.com/users/code-dot-org/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/code-dot-org/subscriptions","organizations_url":"https://api.github.com/users/code-dot-org/orgs","repos_url":"https://api.github.com/users/code-dot-org/repos","events_url":"https://api.github.com/users/code-dot-org/events{/privacy}","received_events_url":"https://api.github.com/users/code-dot-org/received_events","type":"Organization","site_admin":false},"repo":{"id":24250009,"name":"code-dot-org","full_name":"code-dot-org/code-dot-org","owner":{"login":"code-dot-org","id":5124627,"avatar_url":"https://avatars.githubusercontent.com/u/5124627?v=3","gravatar_id":"","url":"https://api.github.com/users/code-dot-org","html_url":"https://github.com/code-dot-org","followers_url":"https://api.github.com/users/code-dot-org/followers","following_url":"https://api.github.com/users/code-dot-org/following{/other_user}","gists_url":"https://api.github.com/users/code-dot-org/gists{/gist_id}","starred_url":"https://api.github.com/users/code-dot-org/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/code-dot-org/subscriptions","organizations_url":"https://api.github.com/users/code-dot-org/orgs","repos_url":"https://api.github.com/users/code-dot-org/repos","events_url":"https://api.github.com/users/code-dot-org/events{/privacy}","received_events_url":"https://api.github.com/users/code-dot-org/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/code-dot-org/code-dot-org","description":"The code powering code.org and studio.code.org","fork":false,"url":"https://api.github.com/repos/code-dot-org/code-dot-org","forks_url":"https://api.github.com/repos/code-dot-org/code-dot-org/forks","keys_url":"https://api.github.com/repos/code-dot-org/code-dot-org/keys{/key_id}","collaborators_url":"https://api.github.com/repos/code-dot-org/code-dot-org/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/code-dot-org/code-dot-org/teams","hooks_url":"https://api.github.com/repos/code-dot-org/code-dot-org/hooks","issue_events_url":"https://api.github.com/repos/code-dot-org/code-dot-org/issues/events{/number}","events_url":"https://api.github.com/repos/code-dot-org/code-dot-org/events","assignees_url":"https://api.github.com/repos/code-dot-org/code-dot-org/assignees{/user}","branches_url":"https://api.github.com/repos/code-dot-org/code-dot-org/branches{/branch}","tags_url":"https://api.github.com/repos/code-dot-org/code-dot-org/tags","blobs_url":"https://api.github.com/repos/code-dot-org/code-dot-org/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/code-dot-org/code-dot-org/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/code-dot-org/code-dot-org/git/refs{/sha}","trees_url":"https://api.github.com/repos/code-dot-org/code-dot-org/git/trees{/sha}","statuses_url":"https://api.github.com/repos/code-dot-org/code-dot-org/statuses/{sha}","languages_url":"https://api.github.com/repos/code-dot-org/code-dot-org/languages","stargazers_url":"https://api.github.com/repos/code-dot-org/code-dot-org/stargazers","contributors_url":"https://api.github.com/repos/code-dot-org/code-dot-org/contributors","subscribers_url":"https://api.github.com/repos/code-dot-org/code-dot-org/subscribers","subscription_url":"https://api.github.com/repos/code-dot-org/code-dot-org/subscription","commits_url":"https://api.github.com/repos/code-dot-org/code-dot-org/commits{/sha}","git_commits_url":"https://api.github.com/repos/code-dot-org/code-dot-org/git/commits{/sha}","comments_url":"https://api.github.com/repos/code-dot-org/code-dot-org/comments{/number}","issue_comment_url":"https://api.github.com/repos/code-dot-org/code-dot-org/issues/comments{/number}","contents_url":"https://api.github.com/repos/code-dot-org/code-dot-org/contents/{+path}","compare_url":"https://api.github.com/repos/code-dot-org/code-dot-org/compare/{base}...{head}","merges_url":"https://api.github.com/repos/code-dot-org/code-dot-org/merges","archive_url":"https://api.github.com/repos/code-dot-org/code-dot-org/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/code-dot-org/code-dot-org/downloads","issues_url":"https://api.github.com/repos/code-dot-org/code-dot-org/issues{/number}","pulls_url":"https://api.github.com/repos/code-dot-org/code-dot-org/pulls{/number}","milestones_url":"https://api.github.com/repos/code-dot-org/code-dot-org/milestones{/number}","notifications_url":"https://api.github.com/repos/code-dot-org/code-dot-org/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/code-dot-org/code-dot-org/labels{/name}","releases_url":"https://api.github.com/repos/code-dot-org/code-dot-org/releases{/id}","created_at":"2014-09-20T00:46:11Z","updated_at":"2015-08-21T05:47:46Z","pushed_at":"2015-08-21T18:04:14Z","git_url":"git://github.com/code-dot-org/code-dot-org.git","ssh_url":"git@github.com:code-dot-org/code-dot-org.git","clone_url":"https://github.com/code-dot-org/code-dot-org.git","svn_url":"https://github.com/code-dot-org/code-dot-org","homepage":"http://code.org","size":2478660,"stargazers_count":53,"watchers_count":53,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":37,"mirror_url":null,"open_issues_count":33,"forks":37,"open_issues":33,"watchers":53,"default_branch":"staging"}},"_links":{"self":{"href":"https://api.github.com/repos/code-dot-org/code-dot-org/pulls/3628"},"html":{"href":"https://github.com/code-dot-org/code-dot-org/pull/3628"},"issue":{"href":"https://api.github.com/repos/code-dot-org/code-dot-org/issues/3628"},"comments":{"href":"https://api.github.com/repos/code-dot-org/code-dot-org/issues/3628/comments"},"review_comments":{"href":"https://api.github.com/repos/code-dot-org/code-dot-org/pulls/3628/comments"},"review_comment":{"href":"https://api.github.com/repos/code-dot-org/code-dot-org/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/code-dot-org/code-dot-org/pulls/3628/commits"},"statuses":{"href":"https://api.github.com/repos/code-dot-org/code-dot-org/statuses/3b627d73c79eed7521ffbf5e742fa8c600339eb4"}}}}