{"action":"closed","number":174,"pull_request":{"url":"https://api.github.com/repos/edx-solutions/api-integration/pulls/174","id":234173697,"node_id":"MDExOlB1bGxSZXF1ZXN0MjM0MTczNjk3","html_url":"https://github.com/edx-solutions/api-integration/pull/174","diff_url":"https://github.com/edx-solutions/api-integration/pull/174.diff","patch_url":"https://github.com/edx-solutions/api-integration/pull/174.patch","issue_url":"https://api.github.com/repos/edx-solutions/api-integration/issues/174","number":174,"state":"closed","locked":false,"title":"[MCKIN-8963] Optimize CoursesRolesList.get","user":{"login":"UmanShahzad","id":10018065,"node_id":"MDQ6VXNlcjEwMDE4MDY1","avatar_url":"https://avatars0.githubusercontent.com/u/10018065?v=4","gravatar_id":"","url":"https://api.github.com/users/UmanShahzad","html_url":"https://github.com/UmanShahzad","followers_url":"https://api.github.com/users/UmanShahzad/followers","following_url":"https://api.github.com/users/UmanShahzad/following{/other_user}","gists_url":"https://api.github.com/users/UmanShahzad/gists{/gist_id}","starred_url":"https://api.github.com/users/UmanShahzad/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/UmanShahzad/subscriptions","organizations_url":"https://api.github.com/users/UmanShahzad/orgs","repos_url":"https://api.github.com/users/UmanShahzad/repos","events_url":"https://api.github.com/users/UmanShahzad/events{/privacy}","received_events_url":"https://api.github.com/users/UmanShahzad/received_events","type":"User","site_admin":false},"body":"The API was making at least 4 DB calls to get data from the same User table, and then doing for loops over all that data up to 3 times to populate a list and filter things down.\r\n\r\nThis kills the for loop and makes 1 DB call.\r\n\r\nTest instructions:\r\n\r\n1. Start up the LMS.\r\n1. Do this before and after going onto this branch, and compare the times and outputs. (Remove the `-o` flag and its value to see output).\r\n    ```bash\r\n    curl -X GET \\\r\n           http://lms.mcka.local/api/server/courses/course-v1:edX%2BDemoX%2BDemo_Course/roles/ \\\r\n           -H 'Authorization: Bearer <token>' \\\r\n           -H 'X-Edx-Api-Key: edx_api_key' \\\r\n           -H 'cache-control: no-cache' \\\r\n           -o /dev/null \\\r\n           -sw 'Total: %{time_total}s\\n'\r\n    ```\r\n1. Make sure the resulting list is the same (though order may differ), but that the time taken is less. You can also just use silk.\r\n1. Finally, add a query param like `user_id=2` or `role=assistant` and make sure the returned list was filtered appropriately.\r\n\r\nMy own testing gave this, where the above is the old version, and the bottom is the new:\r\n\r\n![selection_002](https://user-images.githubusercontent.com/10018065/49137154-6e923480-f30d-11e8-8ec6-d1bbdf4e3947.jpg)\r\n","created_at":"2018-11-28T07:27:51Z","updated_at":"2018-12-02T14:14:01Z","closed_at":"2018-12-02T14:14:01Z","merged_at":"2018-12-02T14:14:01Z","merge_commit_sha":"3e87f185e12cb3979af414d007919c438ea9dfe4","assignee":{"login":"UmanShahzad","id":10018065,"node_id":"MDQ6VXNlcjEwMDE4MDY1","avatar_url":"https://avatars0.githubusercontent.com/u/10018065?v=4","gravatar_id":"","url":"https://api.github.com/users/UmanShahzad","html_url":"https://github.com/UmanShahzad","followers_url":"https://api.github.com/users/UmanShahzad/followers","following_url":"https://api.github.com/users/UmanShahzad/following{/other_user}","gists_url":"https://api.github.com/users/UmanShahzad/gists{/gist_id}","starred_url":"https://api.github.com/users/UmanShahzad/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/UmanShahzad/subscriptions","organizations_url":"https://api.github.com/users/UmanShahzad/orgs","repos_url":"https://api.github.com/users/UmanShahzad/repos","events_url":"https://api.github.com/users/UmanShahzad/events{/privacy}","received_events_url":"https://api.github.com/users/UmanShahzad/received_events","type":"User","site_admin":false},"assignees":[{"login":"UmanShahzad","id":10018065,"node_id":"MDQ6VXNlcjEwMDE4MDY1","avatar_url":"https://avatars0.githubusercontent.com/u/10018065?v=4","gravatar_id":"","url":"https://api.github.com/users/UmanShahzad","html_url":"https://github.com/UmanShahzad","followers_url":"https://api.github.com/users/UmanShahzad/followers","following_url":"https://api.github.com/users/UmanShahzad/following{/other_user}","gists_url":"https://api.github.com/users/UmanShahzad/gists{/gist_id}","starred_url":"https://api.github.com/users/UmanShahzad/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/UmanShahzad/subscriptions","organizations_url":"https://api.github.com/users/UmanShahzad/orgs","repos_url":"https://api.github.com/users/UmanShahzad/repos","events_url":"https://api.github.com/users/UmanShahzad/events{/privacy}","received_events_url":"https://api.github.com/users/UmanShahzad/received_events","type":"User","site_admin":false}],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/edx-solutions/api-integration/pulls/174/commits","review_comments_url":"https://api.github.com/repos/edx-solutions/api-integration/pulls/174/comments","review_comment_url":"https://api.github.com/repos/edx-solutions/api-integration/pulls/comments{/number}","comments_url":"https://api.github.com/repos/edx-solutions/api-integration/issues/174/comments","statuses_url":"https://api.github.com/repos/edx-solutions/api-integration/statuses/a109669ec485a73dd458e9455220ac35392b13d7","head":{"label":"edx-solutions:uman/MCKIN-8963","ref":"uman/MCKIN-8963","sha":"a109669ec485a73dd458e9455220ac35392b13d7","user":{"login":"edx-solutions","id":6585054,"node_id":"MDEyOk9yZ2FuaXphdGlvbjY1ODUwNTQ=","avatar_url":"https://avatars3.githubusercontent.com/u/6585054?v=4","gravatar_id":"","url":"https://api.github.com/users/edx-solutions","html_url":"https://github.com/edx-solutions","followers_url":"https://api.github.com/users/edx-solutions/followers","following_url":"https://api.github.com/users/edx-solutions/following{/other_user}","gists_url":"https://api.github.com/users/edx-solutions/gists{/gist_id}","starred_url":"https://api.github.com/users/edx-solutions/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx-solutions/subscriptions","organizations_url":"https://api.github.com/users/edx-solutions/orgs","repos_url":"https://api.github.com/users/edx-solutions/repos","events_url":"https://api.github.com/users/edx-solutions/events{/privacy}","received_events_url":"https://api.github.com/users/edx-solutions/received_events","type":"Organization","site_admin":false},"repo":{"id":61370435,"node_id":"MDEwOlJlcG9zaXRvcnk2MTM3MDQzNQ==","name":"api-integration","full_name":"edx-solutions/api-integration","private":false,"owner":{"login":"edx-solutions","id":6585054,"node_id":"MDEyOk9yZ2FuaXphdGlvbjY1ODUwNTQ=","avatar_url":"https://avatars3.githubusercontent.com/u/6585054?v=4","gravatar_id":"","url":"https://api.github.com/users/edx-solutions","html_url":"https://github.com/edx-solutions","followers_url":"https://api.github.com/users/edx-solutions/followers","following_url":"https://api.github.com/users/edx-solutions/following{/other_user}","gists_url":"https://api.github.com/users/edx-solutions/gists{/gist_id}","starred_url":"https://api.github.com/users/edx-solutions/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx-solutions/subscriptions","organizations_url":"https://api.github.com/users/edx-solutions/orgs","repos_url":"https://api.github.com/users/edx-solutions/repos","events_url":"https://api.github.com/users/edx-solutions/events{/privacy}","received_events_url":"https://api.github.com/users/edx-solutions/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/edx-solutions/api-integration","description":null,"fork":false,"url":"https://api.github.com/repos/edx-solutions/api-integration","forks_url":"https://api.github.com/repos/edx-solutions/api-integration/forks","keys_url":"https://api.github.com/repos/edx-solutions/api-integration/keys{/key_id}","collaborators_url":"https://api.github.com/repos/edx-solutions/api-integration/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/edx-solutions/api-integration/teams","hooks_url":"https://api.github.com/repos/edx-solutions/api-integration/hooks","issue_events_url":"https://api.github.com/repos/edx-solutions/api-integration/issues/events{/number}","events_url":"https://api.github.com/repos/edx-solutions/api-integration/events","assignees_url":"https://api.github.com/repos/edx-solutions/api-integration/assignees{/user}","branches_url":"https://api.github.com/repos/edx-solutions/api-integration/branches{/branch}","tags_url":"https://api.github.com/repos/edx-solutions/api-integration/tags","blobs_url":"https://api.github.com/repos/edx-solutions/api-integration/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/edx-solutions/api-integration/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/edx-solutions/api-integration/git/refs{/sha}","trees_url":"https://api.github.com/repos/edx-solutions/api-integration/git/trees{/sha}","statuses_url":"https://api.github.com/repos/edx-solutions/api-integration/statuses/{sha}","languages_url":"https://api.github.com/repos/edx-solutions/api-integration/languages","stargazers_url":"https://api.github.com/repos/edx-solutions/api-integration/stargazers","contributors_url":"https://api.github.com/repos/edx-solutions/api-integration/contributors","subscribers_url":"https://api.github.com/repos/edx-solutions/api-integration/subscribers","subscription_url":"https://api.github.com/repos/edx-solutions/api-integration/subscription","commits_url":"https://api.github.com/repos/edx-solutions/api-integration/commits{/sha}","git_commits_url":"https://api.github.com/repos/edx-solutions/api-integration/git/commits{/sha}","comments_url":"https://api.github.com/repos/edx-solutions/api-integration/comments{/number}","issue_comment_url":"https://api.github.com/repos/edx-solutions/api-integration/issues/comments{/number}","contents_url":"https://api.github.com/repos/edx-solutions/api-integration/contents/{+path}","compare_url":"https://api.github.com/repos/edx-solutions/api-integration/compare/{base}...{head}","merges_url":"https://api.github.com/repos/edx-solutions/api-integration/merges","archive_url":"https://api.github.com/repos/edx-solutions/api-integration/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/edx-solutions/api-integration/downloads","issues_url":"https://api.github.com/repos/edx-solutions/api-integration/issues{/number}","pulls_url":"https://api.github.com/repos/edx-solutions/api-integration/pulls{/number}","milestones_url":"https://api.github.com/repos/edx-solutions/api-integration/milestones{/number}","notifications_url":"https://api.github.com/repos/edx-solutions/api-integration/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/edx-solutions/api-integration/labels{/name}","releases_url":"https://api.github.com/repos/edx-solutions/api-integration/releases{/id}","deployments_url":"https://api.github.com/repos/edx-solutions/api-integration/deployments","created_at":"2016-06-17T11:57:41Z","updated_at":"2018-12-01T13:33:58Z","pushed_at":"2018-12-02T14:14:01Z","git_url":"git://github.com/edx-solutions/api-integration.git","ssh_url":"git@github.com:edx-solutions/api-integration.git","clone_url":"https://github.com/edx-solutions/api-integration.git","svn_url":"https://github.com/edx-solutions/api-integration","homepage":null,"size":1059,"stargazers_count":2,"watchers_count":2,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":8,"mirror_url":null,"archived":false,"open_issues_count":1,"license":{"key":"agpl-3.0","name":"GNU Affero General Public License v3.0","spdx_id":"AGPL-3.0","url":"https://api.github.com/licenses/agpl-3.0","node_id":"MDc6TGljZW5zZTE="},"forks":8,"open_issues":1,"watchers":2,"default_branch":"master"}},"base":{"label":"edx-solutions:master","ref":"master","sha":"0ea2f7b18efb63019ed27966c164daa6db47b8aa","user":{"login":"edx-solutions","id":6585054,"node_id":"MDEyOk9yZ2FuaXphdGlvbjY1ODUwNTQ=","avatar_url":"https://avatars3.githubusercontent.com/u/6585054?v=4","gravatar_id":"","url":"https://api.github.com/users/edx-solutions","html_url":"https://github.com/edx-solutions","followers_url":"https://api.github.com/users/edx-solutions/followers","following_url":"https://api.github.com/users/edx-solutions/following{/other_user}","gists_url":"https://api.github.com/users/edx-solutions/gists{/gist_id}","starred_url":"https://api.github.com/users/edx-solutions/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx-solutions/subscriptions","organizations_url":"https://api.github.com/users/edx-solutions/orgs","repos_url":"https://api.github.com/users/edx-solutions/repos","events_url":"https://api.github.com/users/edx-solutions/events{/privacy}","received_events_url":"https://api.github.com/users/edx-solutions/received_events","type":"Organization","site_admin":false},"repo":{"id":61370435,"node_id":"MDEwOlJlcG9zaXRvcnk2MTM3MDQzNQ==","name":"api-integration","full_name":"edx-solutions/api-integration","private":false,"owner":{"login":"edx-solutions","id":6585054,"node_id":"MDEyOk9yZ2FuaXphdGlvbjY1ODUwNTQ=","avatar_url":"https://avatars3.githubusercontent.com/u/6585054?v=4","gravatar_id":"","url":"https://api.github.com/users/edx-solutions","html_url":"https://github.com/edx-solutions","followers_url":"https://api.github.com/users/edx-solutions/followers","following_url":"https://api.github.com/users/edx-solutions/following{/other_user}","gists_url":"https://api.github.com/users/edx-solutions/gists{/gist_id}","starred_url":"https://api.github.com/users/edx-solutions/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx-solutions/subscriptions","organizations_url":"https://api.github.com/users/edx-solutions/orgs","repos_url":"https://api.github.com/users/edx-solutions/repos","events_url":"https://api.github.com/users/edx-solutions/events{/privacy}","received_events_url":"https://api.github.com/users/edx-solutions/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/edx-solutions/api-integration","description":null,"fork":false,"url":"https://api.github.com/repos/edx-solutions/api-integration","forks_url":"https://api.github.com/repos/edx-solutions/api-integration/forks","keys_url":"https://api.github.com/repos/edx-solutions/api-integration/keys{/key_id}","collaborators_url":"https://api.github.com/repos/edx-solutions/api-integration/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/edx-solutions/api-integration/teams","hooks_url":"https://api.github.com/repos/edx-solutions/api-integration/hooks","issue_events_url":"https://api.github.com/repos/edx-solutions/api-integration/issues/events{/number}","events_url":"https://api.github.com/repos/edx-solutions/api-integration/events","assignees_url":"https://api.github.com/repos/edx-solutions/api-integration/assignees{/user}","branches_url":"https://api.github.com/repos/edx-solutions/api-integration/branches{/branch}","tags_url":"https://api.github.com/repos/edx-solutions/api-integration/tags","blobs_url":"https://api.github.com/repos/edx-solutions/api-integration/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/edx-solutions/api-integration/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/edx-solutions/api-integration/git/refs{/sha}","trees_url":"https://api.github.com/repos/edx-solutions/api-integration/git/trees{/sha}","statuses_url":"https://api.github.com/repos/edx-solutions/api-integration/statuses/{sha}","languages_url":"https://api.github.com/repos/edx-solutions/api-integration/languages","stargazers_url":"https://api.github.com/repos/edx-solutions/api-integration/stargazers","contributors_url":"https://api.github.com/repos/edx-solutions/api-integration/contributors","subscribers_url":"https://api.github.com/repos/edx-solutions/api-integration/subscribers","subscription_url":"https://api.github.com/repos/edx-solutions/api-integration/subscription","commits_url":"https://api.github.com/repos/edx-solutions/api-integration/commits{/sha}","git_commits_url":"https://api.github.com/repos/edx-solutions/api-integration/git/commits{/sha}","comments_url":"https://api.github.com/repos/edx-solutions/api-integration/comments{/number}","issue_comment_url":"https://api.github.com/repos/edx-solutions/api-integration/issues/comments{/number}","contents_url":"https://api.github.com/repos/edx-solutions/api-integration/contents/{+path}","compare_url":"https://api.github.com/repos/edx-solutions/api-integration/compare/{base}...{head}","merges_url":"https://api.github.com/repos/edx-solutions/api-integration/merges","archive_url":"https://api.github.com/repos/edx-solutions/api-integration/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/edx-solutions/api-integration/downloads","issues_url":"https://api.github.com/repos/edx-solutions/api-integration/issues{/number}","pulls_url":"https://api.github.com/repos/edx-solutions/api-integration/pulls{/number}","milestones_url":"https://api.github.com/repos/edx-solutions/api-integration/milestones{/number}","notifications_url":"https://api.github.com/repos/edx-solutions/api-integration/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/edx-solutions/api-integration/labels{/name}","releases_url":"https://api.github.com/repos/edx-solutions/api-integration/releases{/id}","deployments_url":"https://api.github.com/repos/edx-solutions/api-integration/deployments","created_at":"2016-06-17T11:57:41Z","updated_at":"2018-12-01T13:33:58Z","pushed_at":"2018-12-02T14:14:01Z","git_url":"git://github.com/edx-solutions/api-integration.git","ssh_url":"git@github.com:edx-solutions/api-integration.git","clone_url":"https://github.com/edx-solutions/api-integration.git","svn_url":"https://github.com/edx-solutions/api-integration","homepage":null,"size":1059,"stargazers_count":2,"watchers_count":2,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":8,"mirror_url":null,"archived":false,"open_issues_count":1,"license":{"key":"agpl-3.0","name":"GNU Affero General Public License v3.0","spdx_id":"AGPL-3.0","url":"https://api.github.com/licenses/agpl-3.0","node_id":"MDc6TGljZW5zZTE="},"forks":8,"open_issues":1,"watchers":2,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/edx-solutions/api-integration/pulls/174"},"html":{"href":"https://github.com/edx-solutions/api-integration/pull/174"},"issue":{"href":"https://api.github.com/repos/edx-solutions/api-integration/issues/174"},"comments":{"href":"https://api.github.com/repos/edx-solutions/api-integration/issues/174/comments"},"review_comments":{"href":"https://api.github.com/repos/edx-solutions/api-integration/pulls/174/comments"},"review_comment":{"href":"https://api.github.com/repos/edx-solutions/api-integration/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/edx-solutions/api-integration/pulls/174/commits"},"statuses":{"href":"https://api.github.com/repos/edx-solutions/api-integration/statuses/a109669ec485a73dd458e9455220ac35392b13d7"}},"author_association":"CONTRIBUTOR","merged":true,"mergeable":null,"rebaseable":null,"mergeable_state":"unknown","merged_by":{"login":"UmanShahzad","id":10018065,"node_id":"MDQ6VXNlcjEwMDE4MDY1","avatar_url":"https://avatars0.githubusercontent.com/u/10018065?v=4","gravatar_id":"","url":"https://api.github.com/users/UmanShahzad","html_url":"https://github.com/UmanShahzad","followers_url":"https://api.github.com/users/UmanShahzad/followers","following_url":"https://api.github.com/users/UmanShahzad/following{/other_user}","gists_url":"https://api.github.com/users/UmanShahzad/gists{/gist_id}","starred_url":"https://api.github.com/users/UmanShahzad/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/UmanShahzad/subscriptions","organizations_url":"https://api.github.com/users/UmanShahzad/orgs","repos_url":"https://api.github.com/users/UmanShahzad/repos","events_url":"https://api.github.com/users/UmanShahzad/events{/privacy}","received_events_url":"https://api.github.com/users/UmanShahzad/received_events","type":"User","site_admin":false},"comments":1,"review_comments":15,"maintainer_can_modify":false,"commits":2,"additions":10,"deletions":21,"changed_files":2}}
{"actor":{"display_login":"UmanShahzad"}}