{"action":"closed","issue":{"url":"https://api.github.com/repos/ilios/ilios/issues/1606","repository_url":"https://api.github.com/repos/ilios/ilios","labels_url":"https://api.github.com/repos/ilios/ilios/issues/1606/labels{/name}","comments_url":"https://api.github.com/repos/ilios/ilios/issues/1606/comments","events_url":"https://api.github.com/repos/ilios/ilios/issues/1606/events","html_url":"https://github.com/ilios/ilios/issues/1606","id":180209137,"number":1606,"title":"Be more frugal about updating relationships","user":{"login":"jrjohnson","id":349624,"avatar_url":"https://avatars.githubusercontent.com/u/349624?v=3","gravatar_id":"","url":"https://api.github.com/users/jrjohnson","html_url":"https://github.com/jrjohnson","followers_url":"https://api.github.com/users/jrjohnson/followers","following_url":"https://api.github.com/users/jrjohnson/following{/other_user}","gists_url":"https://api.github.com/users/jrjohnson/gists{/gist_id}","starred_url":"https://api.github.com/users/jrjohnson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jrjohnson/subscriptions","organizations_url":"https://api.github.com/users/jrjohnson/orgs","repos_url":"https://api.github.com/users/jrjohnson/repos","events_url":"https://api.github.com/users/jrjohnson/events{/privacy}","received_events_url":"https://api.github.com/users/jrjohnson/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/ilios/ilios/labels/BUG","name":"BUG","color":"fc2929"},{"url":"https://api.github.com/repos/ilios/ilios/labels/in%20progress","name":"in progress","color":"ededed"}],"state":"closed","locked":false,"assignee":{"login":"jrjohnson","id":349624,"avatar_url":"https://avatars.githubusercontent.com/u/349624?v=3","gravatar_id":"","url":"https://api.github.com/users/jrjohnson","html_url":"https://github.com/jrjohnson","followers_url":"https://api.github.com/users/jrjohnson/followers","following_url":"https://api.github.com/users/jrjohnson/following{/other_user}","gists_url":"https://api.github.com/users/jrjohnson/gists{/gist_id}","starred_url":"https://api.github.com/users/jrjohnson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jrjohnson/subscriptions","organizations_url":"https://api.github.com/users/jrjohnson/orgs","repos_url":"https://api.github.com/users/jrjohnson/repos","events_url":"https://api.github.com/users/jrjohnson/events{/privacy}","received_events_url":"https://api.github.com/users/jrjohnson/received_events","type":"User","site_admin":false},"assignees":[{"login":"jrjohnson","id":349624,"avatar_url":"https://avatars.githubusercontent.com/u/349624?v=3","gravatar_id":"","url":"https://api.github.com/users/jrjohnson","html_url":"https://github.com/jrjohnson","followers_url":"https://api.github.com/users/jrjohnson/followers","following_url":"https://api.github.com/users/jrjohnson/following{/other_user}","gists_url":"https://api.github.com/users/jrjohnson/gists{/gist_id}","starred_url":"https://api.github.com/users/jrjohnson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jrjohnson/subscriptions","organizations_url":"https://api.github.com/users/jrjohnson/orgs","repos_url":"https://api.github.com/users/jrjohnson/repos","events_url":"https://api.github.com/users/jrjohnson/events{/privacy}","received_events_url":"https://api.github.com/users/jrjohnson/received_events","type":"User","site_admin":false}],"milestone":null,"comments":2,"created_at":"2016-09-30T02:56:22Z","updated_at":"2016-10-09T00:38:46Z","closed_at":"2016-10-09T00:38:46Z","body":"Anytime an API request comes in for an endpoint we clear all of the relationships and then rebuild them from the sent data.  Instead we should only change those items which have changed.  This may improve some deadlock issue and will also have the benefit of only placing actual changes into the audit log.  Currently every request indicates that it has changed relationships.\r\n\r\nThis might look like:\r\n```php\r\n  /**\r\n     * @param Collection $users\r\n     */\r\n    public function setUsers(Collection $users = null)\r\n    {\r\n        if (is_null($users)) {\r\n            $this->users = new ArrayCollection();\r\n            return;\r\n        }\r\n\r\n        $existingUsers = $this->getUsers();\r\n        $usersToDelete = $existingUsers->filter(function (User $user) use ($users) {\r\n            return !$users->contains($user);\r\n        });\r\n        $usersToAdd = $users->filter(function (User $user) use ($existingUsers) {\r\n            return !$existingUsers->contains($user);\r\n        });\r\n\r\n        foreach ($usersToDelete as $user) {\r\n            $this->removeUser($user);\r\n        }\r\n\r\n        foreach ($usersToAdd as $user) {\r\n            $this->addUser($user);\r\n        }\r\n    }\r\n```\r\nMuch of this can likely be generalized into a trait to limit code duplication."}}
{"actor":{"display_login":"jrjohnson"}}