{"action":"created","comment":{"url":"https://api.github.com/repos/ManageIQ/manageiq/pulls/comments/73768523","id":73768523,"diff_hunk":"@@ -0,0 +1,26 @@\n+describe \"Ownership\" do\n+  describe \"reporting\" do\n+    describe \"searching by current ldap group\" do\n+      let(:exp)    { {\"=\"=>{\"field\"=>\"Vm-owned_by_current_ldap_group\", \"value\"=>\"true\"}} }\n+      let(:report) { MiqReport.new.tap {|r| r.db = 'Vm'} }\n+      let(:search_opts) { { :filter => MiqExpression.new(exp), :per_page => 20, :named_scope => :with_miq_group } }\n+\n+      before do\n+        @miq_group = FactoryGirl.create :miq_group\n+        User.current_user = FactoryGirl.create :user,\n+                                               :current_group => @miq_group,\n+                                               :miq_groups => [@miq_group]\n+        expect(User).to receive(:server_timezone).and_return(\"UTC\")","path":"spec/models/mixins/ownership_mixin_spec.rb","position":13,"original_position":13,"commit_id":"e1e41af3a306e8a41b45ccca088c01d327f447de","original_commit_id":"e1e41af3a306e8a41b45ccca088c01d327f447de","user":{"login":"NickLaMuro","id":314014,"avatar_url":"https://avatars.githubusercontent.com/u/314014?v=3","gravatar_id":"","url":"https://api.github.com/users/NickLaMuro","html_url":"https://github.com/NickLaMuro","followers_url":"https://api.github.com/users/NickLaMuro/followers","following_url":"https://api.github.com/users/NickLaMuro/following{/other_user}","gists_url":"https://api.github.com/users/NickLaMuro/gists{/gist_id}","starred_url":"https://api.github.com/users/NickLaMuro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NickLaMuro/subscriptions","organizations_url":"https://api.github.com/users/NickLaMuro/orgs","repos_url":"https://api.github.com/users/NickLaMuro/repos","events_url":"https://api.github.com/users/NickLaMuro/events{/privacy}","received_events_url":"https://api.github.com/users/NickLaMuro/received_events","type":"User","site_admin":false},"body":"Thanks @jrafanie.  First looking into why my tests started failing all of the sudden, but I will see if that helps me out (or at least gives me a pattern to work with).","created_at":"2016-08-05T22:29:57Z","updated_at":"2016-08-05T22:29:57Z","html_url":"https://github.com/ManageIQ/manageiq/pull/10290#discussion_r73768523","pull_request_url":"https://api.github.com/repos/ManageIQ/manageiq/pulls/10290","_links":{"self":{"href":"https://api.github.com/repos/ManageIQ/manageiq/pulls/comments/73768523"},"html":{"href":"https://github.com/ManageIQ/manageiq/pull/10290#discussion_r73768523"},"pull_request":{"href":"https://api.github.com/repos/ManageIQ/manageiq/pulls/10290"}}},"pull_request":{"url":"https://api.github.com/repos/ManageIQ/manageiq/pulls/10290","id":80295502,"html_url":"https://github.com/ManageIQ/manageiq/pull/10290","diff_url":"https://github.com/ManageIQ/manageiq/pull/10290.diff","patch_url":"https://github.com/ManageIQ/manageiq/pull/10290.patch","issue_url":"https://api.github.com/repos/ManageIQ/manageiq/issues/10290","number":10290,"state":"open","locked":false,"title":"Speed up \"VMs & Instances in My LDAP Group\" filter in /vm_or_template/explorer","user":{"login":"NickLaMuro","id":314014,"avatar_url":"https://avatars.githubusercontent.com/u/314014?v=3","gravatar_id":"","url":"https://api.github.com/users/NickLaMuro","html_url":"https://github.com/NickLaMuro","followers_url":"https://api.github.com/users/NickLaMuro/followers","following_url":"https://api.github.com/users/NickLaMuro/following{/other_user}","gists_url":"https://api.github.com/users/NickLaMuro/gists{/gist_id}","starred_url":"https://api.github.com/users/NickLaMuro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NickLaMuro/subscriptions","organizations_url":"https://api.github.com/users/NickLaMuro/orgs","repos_url":"https://api.github.com/users/NickLaMuro/repos","events_url":"https://api.github.com/users/NickLaMuro/events{/privacy}","received_events_url":"https://api.github.com/users/NickLaMuro/received_events","type":"User","site_admin":false},"body":"Purpose or Intent\n-----------------\nSpeeds up \"VMs & Instances in My LDAP Group\" index and ajax calls in the `/vm_or_template` (Services -> Workload) section of the application.\n\n\nHow\n---\nThis adds `virtual_attribute` on to the `ownership_mixin`, which is used by a few classes and makes it so that MiqExpressions will evaluate filter in SQL instead of pulling down all matching records to then interate over and filter in Ruby (causes a Massive N+1 on large datasets).  This requires a join for the `virtual_attribute` to function, so the `with_miq_group` scope does that with out pulling in any extra data, which is added in the controller which uses `MiqReport#paged_view_search` with an `MiqExpression`.\n\n\nMetrics\n-------\nThe data set for these metrics used a DB with approximately 20k `Vm` records.\n\n\n**Before (Regular User)**\n\nStarted POST \"/vm_or_template/tree_select/?id=:id\"...\nCompleted 200 OK in 7242ms (Views: 2.0ms | ActiveRecord: 884.1ms)\n\n|      ms |   bytes |   objects | queries | query (ms) |   rows |\n|    ---: |    ---: |      ---: |    ---: |       ---: |   ---: |\n| 6,043.1 |     N/A | 3,769,724 |      44 |    4,158.3 | 29,709 |\n\n\n**After (Regular User)**\n\nStarted POST \"/vm_or_template/tree_select/?id=:id\"...\nCompleted 200 OK in 823ms (Views: 2.2ms | ActiveRecord: 46.6ms)\n\n|      ms |   bytes |   objects | queries | query (ms) | rows |\n|    ---: |    ---: |      ---: |    ---: |       ---: | ---: |\n|   659.0 |     N/A |   816,802 |      30 |      131.9 |  397 |\n\n\n**Before (Admin)**\n\nStarted POST \"/vm_or_template/tree_select/?id=:id\"...\nCompleted 200 OK in 94316ms (Views: 1.1ms | ActiveRecord: 13351.1ms)\n\n|        ms | bytes |    objects | queries | query (ms) |    rows |\n|      ---: |  ---: |       ---: |    ---: |       ---: |    ---: |\n|  93,770.4 |   N/A | 57,852,016 |     112 |   78,603.0 | 349,084 |\n\n\n\n**After (Admin)**\n\nStarted POST \"/vm_or_template/tree_select/?id=:id\"...\nCompleted 200 OK in 283ms (Views: 1.0ms | ActiveRecord: 12.6ms)\n\n|      ms | bytes |   objects | queries | query (ms) | rows |\n|    ---: |  ---: |      ---: |    ---: |       ---: | ---: |\n|   190.2 |   N/A |    91,554 |      20 |       20.3 |   14 |\n\n\nAdditional Notes\n----------------\n\nThis change drastically reduces the number of `rows` returns, time spend churning in ruby (sometimes to return nothing), decreases bandwidth and memory footprints, but the implementation in the controller is a bit hacky, and most likely requires some other changes now in other places to restore previous functionality.  It also attaches the `with_miq_group` scope to all other calls.  This should be fine for the most part, but could cause other regressions.  Not sure of a better way to limit the inclusion of this scope using the current mechanisms available without some other heavier refactoring required.","created_at":"2016-08-05T19:33:49Z","updated_at":"2016-08-05T22:29:57Z","closed_at":null,"merged_at":null,"merge_commit_sha":"94825bf01d6832afdb93cf88f6df56d3510b9779","assignee":{"login":"Fryguy","id":52120,"avatar_url":"https://avatars.githubusercontent.com/u/52120?v=3","gravatar_id":"","url":"https://api.github.com/users/Fryguy","html_url":"https://github.com/Fryguy","followers_url":"https://api.github.com/users/Fryguy/followers","following_url":"https://api.github.com/users/Fryguy/following{/other_user}","gists_url":"https://api.github.com/users/Fryguy/gists{/gist_id}","starred_url":"https://api.github.com/users/Fryguy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Fryguy/subscriptions","organizations_url":"https://api.github.com/users/Fryguy/orgs","repos_url":"https://api.github.com/users/Fryguy/repos","events_url":"https://api.github.com/users/Fryguy/events{/privacy}","received_events_url":"https://api.github.com/users/Fryguy/received_events","type":"User","site_admin":false},"assignees":[{"login":"Fryguy","id":52120,"avatar_url":"https://avatars.githubusercontent.com/u/52120?v=3","gravatar_id":"","url":"https://api.github.com/users/Fryguy","html_url":"https://github.com/Fryguy","followers_url":"https://api.github.com/users/Fryguy/followers","following_url":"https://api.github.com/users/Fryguy/following{/other_user}","gists_url":"https://api.github.com/users/Fryguy/gists{/gist_id}","starred_url":"https://api.github.com/users/Fryguy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Fryguy/subscriptions","organizations_url":"https://api.github.com/users/Fryguy/orgs","repos_url":"https://api.github.com/users/Fryguy/repos","events_url":"https://api.github.com/users/Fryguy/events{/privacy}","received_events_url":"https://api.github.com/users/Fryguy/received_events","type":"User","site_admin":false}],"milestone":null,"commits_url":"https://api.github.com/repos/ManageIQ/manageiq/pulls/10290/commits","review_comments_url":"https://api.github.com/repos/ManageIQ/manageiq/pulls/10290/comments","review_comment_url":"https://api.github.com/repos/ManageIQ/manageiq/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ManageIQ/manageiq/issues/10290/comments","statuses_url":"https://api.github.com/repos/ManageIQ/manageiq/statuses/e1e41af3a306e8a41b45ccca088c01d327f447de","head":{"label":"NickLaMuro:ownership_mixin_owned_by_ldap_sql","ref":"ownership_mixin_owned_by_ldap_sql","sha":"e1e41af3a306e8a41b45ccca088c01d327f447de","user":{"login":"NickLaMuro","id":314014,"avatar_url":"https://avatars.githubusercontent.com/u/314014?v=3","gravatar_id":"","url":"https://api.github.com/users/NickLaMuro","html_url":"https://github.com/NickLaMuro","followers_url":"https://api.github.com/users/NickLaMuro/followers","following_url":"https://api.github.com/users/NickLaMuro/following{/other_user}","gists_url":"https://api.github.com/users/NickLaMuro/gists{/gist_id}","starred_url":"https://api.github.com/users/NickLaMuro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NickLaMuro/subscriptions","organizations_url":"https://api.github.com/users/NickLaMuro/orgs","repos_url":"https://api.github.com/users/NickLaMuro/repos","events_url":"https://api.github.com/users/NickLaMuro/events{/privacy}","received_events_url":"https://api.github.com/users/NickLaMuro/received_events","type":"User","site_admin":false},"repo":{"id":60729101,"name":"manageiq","full_name":"NickLaMuro/manageiq","owner":{"login":"NickLaMuro","id":314014,"avatar_url":"https://avatars.githubusercontent.com/u/314014?v=3","gravatar_id":"","url":"https://api.github.com/users/NickLaMuro","html_url":"https://github.com/NickLaMuro","followers_url":"https://api.github.com/users/NickLaMuro/followers","following_url":"https://api.github.com/users/NickLaMuro/following{/other_user}","gists_url":"https://api.github.com/users/NickLaMuro/gists{/gist_id}","starred_url":"https://api.github.com/users/NickLaMuro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NickLaMuro/subscriptions","organizations_url":"https://api.github.com/users/NickLaMuro/orgs","repos_url":"https://api.github.com/users/NickLaMuro/repos","events_url":"https://api.github.com/users/NickLaMuro/events{/privacy}","received_events_url":"https://api.github.com/users/NickLaMuro/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/NickLaMuro/manageiq","description":"ManageIQ Cloud Management Platform","fork":true,"url":"https://api.github.com/repos/NickLaMuro/manageiq","forks_url":"https://api.github.com/repos/NickLaMuro/manageiq/forks","keys_url":"https://api.github.com/repos/NickLaMuro/manageiq/keys{/key_id}","collaborators_url":"https://api.github.com/repos/NickLaMuro/manageiq/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/NickLaMuro/manageiq/teams","hooks_url":"https://api.github.com/repos/NickLaMuro/manageiq/hooks","issue_events_url":"https://api.github.com/repos/NickLaMuro/manageiq/issues/events{/number}","events_url":"https://api.github.com/repos/NickLaMuro/manageiq/events","assignees_url":"https://api.github.com/repos/NickLaMuro/manageiq/assignees{/user}","branches_url":"https://api.github.com/repos/NickLaMuro/manageiq/branches{/branch}","tags_url":"https://api.github.com/repos/NickLaMuro/manageiq/tags","blobs_url":"https://api.github.com/repos/NickLaMuro/manageiq/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/NickLaMuro/manageiq/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/NickLaMuro/manageiq/git/refs{/sha}","trees_url":"https://api.github.com/repos/NickLaMuro/manageiq/git/trees{/sha}","statuses_url":"https://api.github.com/repos/NickLaMuro/manageiq/statuses/{sha}","languages_url":"https://api.github.com/repos/NickLaMuro/manageiq/languages","stargazers_url":"https://api.github.com/repos/NickLaMuro/manageiq/stargazers","contributors_url":"https://api.github.com/repos/NickLaMuro/manageiq/contributors","subscribers_url":"https://api.github.com/repos/NickLaMuro/manageiq/subscribers","subscription_url":"https://api.github.com/repos/NickLaMuro/manageiq/subscription","commits_url":"https://api.github.com/repos/NickLaMuro/manageiq/commits{/sha}","git_commits_url":"https://api.github.com/repos/NickLaMuro/manageiq/git/commits{/sha}","comments_url":"https://api.github.com/repos/NickLaMuro/manageiq/comments{/number}","issue_comment_url":"https://api.github.com/repos/NickLaMuro/manageiq/issues/comments{/number}","contents_url":"https://api.github.com/repos/NickLaMuro/manageiq/contents/{+path}","compare_url":"https://api.github.com/repos/NickLaMuro/manageiq/compare/{base}...{head}","merges_url":"https://api.github.com/repos/NickLaMuro/manageiq/merges","archive_url":"https://api.github.com/repos/NickLaMuro/manageiq/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/NickLaMuro/manageiq/downloads","issues_url":"https://api.github.com/repos/NickLaMuro/manageiq/issues{/number}","pulls_url":"https://api.github.com/repos/NickLaMuro/manageiq/pulls{/number}","milestones_url":"https://api.github.com/repos/NickLaMuro/manageiq/milestones{/number}","notifications_url":"https://api.github.com/repos/NickLaMuro/manageiq/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/NickLaMuro/manageiq/labels{/name}","releases_url":"https://api.github.com/repos/NickLaMuro/manageiq/releases{/id}","deployments_url":"https://api.github.com/repos/NickLaMuro/manageiq/deployments","created_at":"2016-06-08T20:36:58Z","updated_at":"2016-06-08T20:37:19Z","pushed_at":"2016-08-05T19:31:22Z","git_url":"git://github.com/NickLaMuro/manageiq.git","ssh_url":"git@github.com:NickLaMuro/manageiq.git","clone_url":"https://github.com/NickLaMuro/manageiq.git","svn_url":"https://github.com/NickLaMuro/manageiq","homepage":"manageiq.org","size":143442,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"ManageIQ:master","ref":"master","sha":"df7d0604c250e5049f19c08b0681262d4883067e","user":{"login":"ManageIQ","id":1125575,"avatar_url":"https://avatars.githubusercontent.com/u/1125575?v=3","gravatar_id":"","url":"https://api.github.com/users/ManageIQ","html_url":"https://github.com/ManageIQ","followers_url":"https://api.github.com/users/ManageIQ/followers","following_url":"https://api.github.com/users/ManageIQ/following{/other_user}","gists_url":"https://api.github.com/users/ManageIQ/gists{/gist_id}","starred_url":"https://api.github.com/users/ManageIQ/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ManageIQ/subscriptions","organizations_url":"https://api.github.com/users/ManageIQ/orgs","repos_url":"https://api.github.com/users/ManageIQ/repos","events_url":"https://api.github.com/users/ManageIQ/events{/privacy}","received_events_url":"https://api.github.com/users/ManageIQ/received_events","type":"Organization","site_admin":false},"repo":{"id":20789757,"name":"manageiq","full_name":"ManageIQ/manageiq","owner":{"login":"ManageIQ","id":1125575,"avatar_url":"https://avatars.githubusercontent.com/u/1125575?v=3","gravatar_id":"","url":"https://api.github.com/users/ManageIQ","html_url":"https://github.com/ManageIQ","followers_url":"https://api.github.com/users/ManageIQ/followers","following_url":"https://api.github.com/users/ManageIQ/following{/other_user}","gists_url":"https://api.github.com/users/ManageIQ/gists{/gist_id}","starred_url":"https://api.github.com/users/ManageIQ/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ManageIQ/subscriptions","organizations_url":"https://api.github.com/users/ManageIQ/orgs","repos_url":"https://api.github.com/users/ManageIQ/repos","events_url":"https://api.github.com/users/ManageIQ/events{/privacy}","received_events_url":"https://api.github.com/users/ManageIQ/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ManageIQ/manageiq","description":"ManageIQ Open-Source Management Platform","fork":false,"url":"https://api.github.com/repos/ManageIQ/manageiq","forks_url":"https://api.github.com/repos/ManageIQ/manageiq/forks","keys_url":"https://api.github.com/repos/ManageIQ/manageiq/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ManageIQ/manageiq/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ManageIQ/manageiq/teams","hooks_url":"https://api.github.com/repos/ManageIQ/manageiq/hooks","issue_events_url":"https://api.github.com/repos/ManageIQ/manageiq/issues/events{/number}","events_url":"https://api.github.com/repos/ManageIQ/manageiq/events","assignees_url":"https://api.github.com/repos/ManageIQ/manageiq/assignees{/user}","branches_url":"https://api.github.com/repos/ManageIQ/manageiq/branches{/branch}","tags_url":"https://api.github.com/repos/ManageIQ/manageiq/tags","blobs_url":"https://api.github.com/repos/ManageIQ/manageiq/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ManageIQ/manageiq/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ManageIQ/manageiq/git/refs{/sha}","trees_url":"https://api.github.com/repos/ManageIQ/manageiq/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ManageIQ/manageiq/statuses/{sha}","languages_url":"https://api.github.com/repos/ManageIQ/manageiq/languages","stargazers_url":"https://api.github.com/repos/ManageIQ/manageiq/stargazers","contributors_url":"https://api.github.com/repos/ManageIQ/manageiq/contributors","subscribers_url":"https://api.github.com/repos/ManageIQ/manageiq/subscribers","subscription_url":"https://api.github.com/repos/ManageIQ/manageiq/subscription","commits_url":"https://api.github.com/repos/ManageIQ/manageiq/commits{/sha}","git_commits_url":"https://api.github.com/repos/ManageIQ/manageiq/git/commits{/sha}","comments_url":"https://api.github.com/repos/ManageIQ/manageiq/comments{/number}","issue_comment_url":"https://api.github.com/repos/ManageIQ/manageiq/issues/comments{/number}","contents_url":"https://api.github.com/repos/ManageIQ/manageiq/contents/{+path}","compare_url":"https://api.github.com/repos/ManageIQ/manageiq/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ManageIQ/manageiq/merges","archive_url":"https://api.github.com/repos/ManageIQ/manageiq/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ManageIQ/manageiq/downloads","issues_url":"https://api.github.com/repos/ManageIQ/manageiq/issues{/number}","pulls_url":"https://api.github.com/repos/ManageIQ/manageiq/pulls{/number}","milestones_url":"https://api.github.com/repos/ManageIQ/manageiq/milestones{/number}","notifications_url":"https://api.github.com/repos/ManageIQ/manageiq/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ManageIQ/manageiq/labels{/name}","releases_url":"https://api.github.com/repos/ManageIQ/manageiq/releases{/id}","deployments_url":"https://api.github.com/repos/ManageIQ/manageiq/deployments","created_at":"2014-06-13T02:31:26Z","updated_at":"2016-08-04T01:15:42Z","pushed_at":"2016-08-05T22:26:36Z","git_url":"git://github.com/ManageIQ/manageiq.git","ssh_url":"git@github.com:ManageIQ/manageiq.git","clone_url":"https://github.com/ManageIQ/manageiq.git","svn_url":"https://github.com/ManageIQ/manageiq","homepage":"manageiq.org","size":191644,"stargazers_count":299,"watchers_count":299,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":332,"mirror_url":null,"open_issues_count":738,"forks":332,"open_issues":738,"watchers":299,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ManageIQ/manageiq/pulls/10290"},"html":{"href":"https://github.com/ManageIQ/manageiq/pull/10290"},"issue":{"href":"https://api.github.com/repos/ManageIQ/manageiq/issues/10290"},"comments":{"href":"https://api.github.com/repos/ManageIQ/manageiq/issues/10290/comments"},"review_comments":{"href":"https://api.github.com/repos/ManageIQ/manageiq/pulls/10290/comments"},"review_comment":{"href":"https://api.github.com/repos/ManageIQ/manageiq/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ManageIQ/manageiq/pulls/10290/commits"},"statuses":{"href":"https://api.github.com/repos/ManageIQ/manageiq/statuses/e1e41af3a306e8a41b45ccca088c01d327f447de"}}}}
{"actor":{"display_login":"NickLaMuro"}}