{"action":"created","issue":{"url":"https://api.github.com/repos/balderdashy/waterline/issues/829","labels_url":"https://api.github.com/repos/balderdashy/waterline/issues/829/labels{/name}","comments_url":"https://api.github.com/repos/balderdashy/waterline/issues/829/comments","events_url":"https://api.github.com/repos/balderdashy/waterline/issues/829/events","html_url":"https://github.com/balderdashy/waterline/pull/829","id":56901702,"number":829,"title":"Decreased processing time by making queries which involve population more efficient","user":{"login":"nbiton","id":2662819,"avatar_url":"https://avatars.githubusercontent.com/u/2662819?v=3","gravatar_id":"","url":"https://api.github.com/users/nbiton","html_url":"https://github.com/nbiton","followers_url":"https://api.github.com/users/nbiton/followers","following_url":"https://api.github.com/users/nbiton/following{/other_user}","gists_url":"https://api.github.com/users/nbiton/gists{/gist_id}","starred_url":"https://api.github.com/users/nbiton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nbiton/subscriptions","organizations_url":"https://api.github.com/users/nbiton/orgs","repos_url":"https://api.github.com/users/nbiton/repos","events_url":"https://api.github.com/users/nbiton/events{/privacy}","received_events_url":"https://api.github.com/users/nbiton/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-02-07T07:30:11Z","updated_at":"2015-02-15T23:31:10Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/balderdashy/waterline/pulls/829","html_url":"https://github.com/balderdashy/waterline/pull/829","diff_url":"https://github.com/balderdashy/waterline/pull/829.diff","patch_url":"https://github.com/balderdashy/waterline/pull/829.patch"},"body":"This PR includes two simple changes which vastly improved the performance for queries which populate records with associations to other models which also have associations:\r\n- Avoiding _.cloneDeep of the model's attributes definition for each of the records which should be populated, and instead using _.cloneDeep only the attributes which are associations.\r\n- Avoiding \"instrumenting\" the model records for associations, if those records were retrieved only to populate the main records which were queried (so the associations wouldn't be used anyway).\r\n\r\nThese changes have decreased the processing time on my tests of querying a model which populates three associations to models which also have associations to around than 30% of what it was before."},"comment":{"url":"https://api.github.com/repos/balderdashy/waterline/issues/comments/74443706","html_url":"https://github.com/balderdashy/waterline/pull/829#issuecomment-74443706","issue_url":"https://api.github.com/repos/balderdashy/waterline/issues/829","id":74443706,"user":{"login":"devinivy","id":3150233,"avatar_url":"https://avatars.githubusercontent.com/u/3150233?v=3","gravatar_id":"","url":"https://api.github.com/users/devinivy","html_url":"https://github.com/devinivy","followers_url":"https://api.github.com/users/devinivy/followers","following_url":"https://api.github.com/users/devinivy/following{/other_user}","gists_url":"https://api.github.com/users/devinivy/gists{/gist_id}","starred_url":"https://api.github.com/users/devinivy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/devinivy/subscriptions","organizations_url":"https://api.github.com/users/devinivy/orgs","repos_url":"https://api.github.com/users/devinivy/repos","events_url":"https://api.github.com/users/devinivy/events{/privacy}","received_events_url":"https://api.github.com/users/devinivy/received_events","type":"User","site_admin":false},"created_at":"2015-02-15T23:31:10Z","updated_at":"2015-02-15T23:31:10Z","body":"I looked through the changes.  My only concern is that it's often right but perhaps generally wrong to assume that you shouldn't be able to `add` or `remove` on populated records.  One way you're saving time is by,\r\n> Avoiding \"instrumenting\" the model records for associations, if those records were retrieved only to populate the main records which were queried _(so the associations wouldn't be used anyway)_.\r\n\r\nI imagine some use-case like this,\r\n```\r\nDirectory.findOne({name: 'waterline2'}).populate('files')\r\n.then(function(directory) {\r\n\r\n    var file;\r\n    for (var i = 0; i < directory.files.length; i++) {\r\n        file = directory.files[i];\r\n        file.collaborators.add(someId);\r\n        file.save();\r\n    }\r\n\r\n});\r\n```"}}