{"action":"created","comment":{"url":"https://api.github.com/repos/cubing/worldcubeassociation.org/pulls/comments/79303945","id":79303945,"diff_hunk":"@@ -658,20 +660,16 @@ def started?\n     !start_date.nil? && start_date < Date.today\n   end\n \n-  def country_name\n-    country ? country.name : nil\n-  end\n-\n-  def country\n-    Country.find_by_id(countryId)\n-  end\n-\n   def organizers_or_delegates\n     self.organizers.empty? ? self.delegates : self.organizers\n   end\n \n   def continent\n-    country ? Continent.find_by_id(country.continentId) : nil\n+    # NOTE: Doing this find is ok right now, because it's only called once when\n+    # sending reports. However if at some point we want to include the continent\n+    # in some competitions list, we should define an association the same way\n+    # we do for country to avoid \"hidden\" N+1 query.\n+    Continent.find_by_id(country.continentId)","path":"WcaOnRails/app/models/competition.rb","position":40,"original_position":40,"commit_id":"b10087d3973e1d98d8ec84685c65959964147718","original_commit_id":"b10087d3973e1d98d8ec84685c65959964147718","user":{"login":"viroulep","id":1007485,"avatar_url":"https://avatars.githubusercontent.com/u/1007485?v=3","gravatar_id":"","url":"https://api.github.com/users/viroulep","html_url":"https://github.com/viroulep","followers_url":"https://api.github.com/users/viroulep/followers","following_url":"https://api.github.com/users/viroulep/following{/other_user}","gists_url":"https://api.github.com/users/viroulep/gists{/gist_id}","starred_url":"https://api.github.com/users/viroulep/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/viroulep/subscriptions","organizations_url":"https://api.github.com/users/viroulep/orgs","repos_url":"https://api.github.com/users/viroulep/repos","events_url":"https://api.github.com/users/viroulep/events{/privacy}","received_events_url":"https://api.github.com/users/viroulep/received_events","type":"User","site_admin":false},"body":"I think so yes!","created_at":"2016-09-18T11:47:57Z","updated_at":"2016-09-18T11:47:57Z","html_url":"https://github.com/cubing/worldcubeassociation.org/pull/905#discussion_r79303945","pull_request_url":"https://api.github.com/repos/cubing/worldcubeassociation.org/pulls/905","_links":{"self":{"href":"https://api.github.com/repos/cubing/worldcubeassociation.org/pulls/comments/79303945"},"html":{"href":"https://github.com/cubing/worldcubeassociation.org/pull/905#discussion_r79303945"},"pull_request":{"href":"https://api.github.com/repos/cubing/worldcubeassociation.org/pulls/905"}}},"pull_request":{"url":"https://api.github.com/repos/cubing/worldcubeassociation.org/pulls/905","id":85706932,"html_url":"https://github.com/cubing/worldcubeassociation.org/pull/905","diff_url":"https://github.com/cubing/worldcubeassociation.org/pull/905.diff","patch_url":"https://github.com/cubing/worldcubeassociation.org/pull/905.patch","issue_url":"https://api.github.com/repos/cubing/worldcubeassociation.org/issues/905","number":905,"state":"open","locked":false,"title":"Associate a country to a competition.","user":{"login":"viroulep","id":1007485,"avatar_url":"https://avatars.githubusercontent.com/u/1007485?v=3","gravatar_id":"","url":"https://api.github.com/users/viroulep","html_url":"https://github.com/viroulep","followers_url":"https://api.github.com/users/viroulep/followers","following_url":"https://api.github.com/users/viroulep/following{/other_user}","gists_url":"https://api.github.com/users/viroulep/gists{/gist_id}","starred_url":"https://api.github.com/users/viroulep/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/viroulep/subscriptions","organizations_url":"https://api.github.com/users/viroulep/orgs","repos_url":"https://api.github.com/users/viroulep/repos","events_url":"https://api.github.com/users/viroulep/events{/privacy}","received_events_url":"https://api.github.com/users/viroulep/received_events","type":"User","site_admin":false},"body":"This is a performance PR again.\r\n\r\nI succeeded in running newrelic locally and noticed what @timhabermaas was talking about in #903: the `/competitions` fires a lot of mysql.find on countries (one per competition actually...) so I looked a bit into it, and associating a country to a competition revealed the N+1 query.\r\n\r\nThe performance improvement is not significant on my computer (~100 finds on countries are evaluated to 70ms) out of a ~1200ms total load time (It may be more significant on prod). There may be some more room for improvements, but they would be in the rendering and not on the mysql side.\r\n\r\nI noticed we initially had a check in competition.country, is there any case where the competition would not have a country which is not in the db?\r\n\r\nNote: the `/competitions/mine` also has the same issue on `country` and `delegate_report`, this is less annoying but could still be an issue for people with a lot of comps. However the way the competitions are retrieved [here](https://github.com/cubing/worldcubeassociation.org/blob/89f37a7c479063e5a1b789056e1b10e7ef40e216/WcaOnRails/app/controllers/competitions_controller.rb#L323) makes the changes awkward: it leads to unused eager loading in pages using `User` without using their comps. So I did not included them.","created_at":"2016-09-18T11:18:25Z","updated_at":"2016-09-18T11:47:57Z","closed_at":null,"merged_at":null,"merge_commit_sha":"864c6c4bad1fbc2b586e1d58d3029ae9e3f52840","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/cubing/worldcubeassociation.org/pulls/905/commits","review_comments_url":"https://api.github.com/repos/cubing/worldcubeassociation.org/pulls/905/comments","review_comment_url":"https://api.github.com/repos/cubing/worldcubeassociation.org/pulls/comments{/number}","comments_url":"https://api.github.com/repos/cubing/worldcubeassociation.org/issues/905/comments","statuses_url":"https://api.github.com/repos/cubing/worldcubeassociation.org/statuses/b10087d3973e1d98d8ec84685c65959964147718","head":{"label":"viroulep:fix-n+1-country","ref":"fix-n+1-country","sha":"b10087d3973e1d98d8ec84685c65959964147718","user":{"login":"viroulep","id":1007485,"avatar_url":"https://avatars.githubusercontent.com/u/1007485?v=3","gravatar_id":"","url":"https://api.github.com/users/viroulep","html_url":"https://github.com/viroulep","followers_url":"https://api.github.com/users/viroulep/followers","following_url":"https://api.github.com/users/viroulep/following{/other_user}","gists_url":"https://api.github.com/users/viroulep/gists{/gist_id}","starred_url":"https://api.github.com/users/viroulep/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/viroulep/subscriptions","organizations_url":"https://api.github.com/users/viroulep/orgs","repos_url":"https://api.github.com/users/viroulep/repos","events_url":"https://api.github.com/users/viroulep/events{/privacy}","received_events_url":"https://api.github.com/users/viroulep/received_events","type":"User","site_admin":false},"repo":{"id":49994335,"name":"worldcubeassociation.org","full_name":"viroulep/worldcubeassociation.org","owner":{"login":"viroulep","id":1007485,"avatar_url":"https://avatars.githubusercontent.com/u/1007485?v=3","gravatar_id":"","url":"https://api.github.com/users/viroulep","html_url":"https://github.com/viroulep","followers_url":"https://api.github.com/users/viroulep/followers","following_url":"https://api.github.com/users/viroulep/following{/other_user}","gists_url":"https://api.github.com/users/viroulep/gists{/gist_id}","starred_url":"https://api.github.com/users/viroulep/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/viroulep/subscriptions","organizations_url":"https://api.github.com/users/viroulep/orgs","repos_url":"https://api.github.com/users/viroulep/repos","events_url":"https://api.github.com/users/viroulep/events{/privacy}","received_events_url":"https://api.github.com/users/viroulep/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/viroulep/worldcubeassociation.org","description":"[WCA Project] All of the code that runs on worldcubeassociation.org","fork":true,"url":"https://api.github.com/repos/viroulep/worldcubeassociation.org","forks_url":"https://api.github.com/repos/viroulep/worldcubeassociation.org/forks","keys_url":"https://api.github.com/repos/viroulep/worldcubeassociation.org/keys{/key_id}","collaborators_url":"https://api.github.com/repos/viroulep/worldcubeassociation.org/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/viroulep/worldcubeassociation.org/teams","hooks_url":"https://api.github.com/repos/viroulep/worldcubeassociation.org/hooks","issue_events_url":"https://api.github.com/repos/viroulep/worldcubeassociation.org/issues/events{/number}","events_url":"https://api.github.com/repos/viroulep/worldcubeassociation.org/events","assignees_url":"https://api.github.com/repos/viroulep/worldcubeassociation.org/assignees{/user}","branches_url":"https://api.github.com/repos/viroulep/worldcubeassociation.org/branches{/branch}","tags_url":"https://api.github.com/repos/viroulep/worldcubeassociation.org/tags","blobs_url":"https://api.github.com/repos/viroulep/worldcubeassociation.org/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/viroulep/worldcubeassociation.org/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/viroulep/worldcubeassociation.org/git/refs{/sha}","trees_url":"https://api.github.com/repos/viroulep/worldcubeassociation.org/git/trees{/sha}","statuses_url":"https://api.github.com/repos/viroulep/worldcubeassociation.org/statuses/{sha}","languages_url":"https://api.github.com/repos/viroulep/worldcubeassociation.org/languages","stargazers_url":"https://api.github.com/repos/viroulep/worldcubeassociation.org/stargazers","contributors_url":"https://api.github.com/repos/viroulep/worldcubeassociation.org/contributors","subscribers_url":"https://api.github.com/repos/viroulep/worldcubeassociation.org/subscribers","subscription_url":"https://api.github.com/repos/viroulep/worldcubeassociation.org/subscription","commits_url":"https://api.github.com/repos/viroulep/worldcubeassociation.org/commits{/sha}","git_commits_url":"https://api.github.com/repos/viroulep/worldcubeassociation.org/git/commits{/sha}","comments_url":"https://api.github.com/repos/viroulep/worldcubeassociation.org/comments{/number}","issue_comment_url":"https://api.github.com/repos/viroulep/worldcubeassociation.org/issues/comments{/number}","contents_url":"https://api.github.com/repos/viroulep/worldcubeassociation.org/contents/{+path}","compare_url":"https://api.github.com/repos/viroulep/worldcubeassociation.org/compare/{base}...{head}","merges_url":"https://api.github.com/repos/viroulep/worldcubeassociation.org/merges","archive_url":"https://api.github.com/repos/viroulep/worldcubeassociation.org/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/viroulep/worldcubeassociation.org/downloads","issues_url":"https://api.github.com/repos/viroulep/worldcubeassociation.org/issues{/number}","pulls_url":"https://api.github.com/repos/viroulep/worldcubeassociation.org/pulls{/number}","milestones_url":"https://api.github.com/repos/viroulep/worldcubeassociation.org/milestones{/number}","notifications_url":"https://api.github.com/repos/viroulep/worldcubeassociation.org/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/viroulep/worldcubeassociation.org/labels{/name}","releases_url":"https://api.github.com/repos/viroulep/worldcubeassociation.org/releases{/id}","deployments_url":"https://api.github.com/repos/viroulep/worldcubeassociation.org/deployments","created_at":"2016-01-20T01:01:37Z","updated_at":"2016-01-20T01:01:44Z","pushed_at":"2016-09-18T11:02:15Z","git_url":"git://github.com/viroulep/worldcubeassociation.org.git","ssh_url":"git@github.com:viroulep/worldcubeassociation.org.git","clone_url":"https://github.com/viroulep/worldcubeassociation.org.git","svn_url":"https://github.com/viroulep/worldcubeassociation.org","homepage":"https://www.worldcubeassociation.org/","size":56404,"stargazers_count":0,"watchers_count":0,"language":"PHP","has_issues":false,"has_downloads":true,"has_wiki":true,"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":"cubing:master","ref":"master","sha":"89f37a7c479063e5a1b789056e1b10e7ef40e216","user":{"login":"cubing","id":1092267,"avatar_url":"https://avatars.githubusercontent.com/u/1092267?v=3","gravatar_id":"","url":"https://api.github.com/users/cubing","html_url":"https://github.com/cubing","followers_url":"https://api.github.com/users/cubing/followers","following_url":"https://api.github.com/users/cubing/following{/other_user}","gists_url":"https://api.github.com/users/cubing/gists{/gist_id}","starred_url":"https://api.github.com/users/cubing/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cubing/subscriptions","organizations_url":"https://api.github.com/users/cubing/orgs","repos_url":"https://api.github.com/users/cubing/repos","events_url":"https://api.github.com/users/cubing/events{/privacy}","received_events_url":"https://api.github.com/users/cubing/received_events","type":"Organization","site_admin":false},"repo":{"id":34161579,"name":"worldcubeassociation.org","full_name":"cubing/worldcubeassociation.org","owner":{"login":"cubing","id":1092267,"avatar_url":"https://avatars.githubusercontent.com/u/1092267?v=3","gravatar_id":"","url":"https://api.github.com/users/cubing","html_url":"https://github.com/cubing","followers_url":"https://api.github.com/users/cubing/followers","following_url":"https://api.github.com/users/cubing/following{/other_user}","gists_url":"https://api.github.com/users/cubing/gists{/gist_id}","starred_url":"https://api.github.com/users/cubing/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cubing/subscriptions","organizations_url":"https://api.github.com/users/cubing/orgs","repos_url":"https://api.github.com/users/cubing/repos","events_url":"https://api.github.com/users/cubing/events{/privacy}","received_events_url":"https://api.github.com/users/cubing/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/cubing/worldcubeassociation.org","description":"[WCA Project] All of the code that runs on worldcubeassociation.org","fork":false,"url":"https://api.github.com/repos/cubing/worldcubeassociation.org","forks_url":"https://api.github.com/repos/cubing/worldcubeassociation.org/forks","keys_url":"https://api.github.com/repos/cubing/worldcubeassociation.org/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cubing/worldcubeassociation.org/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cubing/worldcubeassociation.org/teams","hooks_url":"https://api.github.com/repos/cubing/worldcubeassociation.org/hooks","issue_events_url":"https://api.github.com/repos/cubing/worldcubeassociation.org/issues/events{/number}","events_url":"https://api.github.com/repos/cubing/worldcubeassociation.org/events","assignees_url":"https://api.github.com/repos/cubing/worldcubeassociation.org/assignees{/user}","branches_url":"https://api.github.com/repos/cubing/worldcubeassociation.org/branches{/branch}","tags_url":"https://api.github.com/repos/cubing/worldcubeassociation.org/tags","blobs_url":"https://api.github.com/repos/cubing/worldcubeassociation.org/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cubing/worldcubeassociation.org/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cubing/worldcubeassociation.org/git/refs{/sha}","trees_url":"https://api.github.com/repos/cubing/worldcubeassociation.org/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cubing/worldcubeassociation.org/statuses/{sha}","languages_url":"https://api.github.com/repos/cubing/worldcubeassociation.org/languages","stargazers_url":"https://api.github.com/repos/cubing/worldcubeassociation.org/stargazers","contributors_url":"https://api.github.com/repos/cubing/worldcubeassociation.org/contributors","subscribers_url":"https://api.github.com/repos/cubing/worldcubeassociation.org/subscribers","subscription_url":"https://api.github.com/repos/cubing/worldcubeassociation.org/subscription","commits_url":"https://api.github.com/repos/cubing/worldcubeassociation.org/commits{/sha}","git_commits_url":"https://api.github.com/repos/cubing/worldcubeassociation.org/git/commits{/sha}","comments_url":"https://api.github.com/repos/cubing/worldcubeassociation.org/comments{/number}","issue_comment_url":"https://api.github.com/repos/cubing/worldcubeassociation.org/issues/comments{/number}","contents_url":"https://api.github.com/repos/cubing/worldcubeassociation.org/contents/{+path}","compare_url":"https://api.github.com/repos/cubing/worldcubeassociation.org/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cubing/worldcubeassociation.org/merges","archive_url":"https://api.github.com/repos/cubing/worldcubeassociation.org/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cubing/worldcubeassociation.org/downloads","issues_url":"https://api.github.com/repos/cubing/worldcubeassociation.org/issues{/number}","pulls_url":"https://api.github.com/repos/cubing/worldcubeassociation.org/pulls{/number}","milestones_url":"https://api.github.com/repos/cubing/worldcubeassociation.org/milestones{/number}","notifications_url":"https://api.github.com/repos/cubing/worldcubeassociation.org/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cubing/worldcubeassociation.org/labels{/name}","releases_url":"https://api.github.com/repos/cubing/worldcubeassociation.org/releases{/id}","deployments_url":"https://api.github.com/repos/cubing/worldcubeassociation.org/deployments","created_at":"2015-04-18T10:21:53Z","updated_at":"2016-09-14T01:08:12Z","pushed_at":"2016-09-18T11:18:25Z","git_url":"git://github.com/cubing/worldcubeassociation.org.git","ssh_url":"git@github.com:cubing/worldcubeassociation.org.git","clone_url":"https://github.com/cubing/worldcubeassociation.org.git","svn_url":"https://github.com/cubing/worldcubeassociation.org","homepage":"https://www.worldcubeassociation.org/","size":56718,"stargazers_count":23,"watchers_count":23,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":29,"mirror_url":null,"open_issues_count":170,"forks":29,"open_issues":170,"watchers":23,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/cubing/worldcubeassociation.org/pulls/905"},"html":{"href":"https://github.com/cubing/worldcubeassociation.org/pull/905"},"issue":{"href":"https://api.github.com/repos/cubing/worldcubeassociation.org/issues/905"},"comments":{"href":"https://api.github.com/repos/cubing/worldcubeassociation.org/issues/905/comments"},"review_comments":{"href":"https://api.github.com/repos/cubing/worldcubeassociation.org/pulls/905/comments"},"review_comment":{"href":"https://api.github.com/repos/cubing/worldcubeassociation.org/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/cubing/worldcubeassociation.org/pulls/905/commits"},"statuses":{"href":"https://api.github.com/repos/cubing/worldcubeassociation.org/statuses/b10087d3973e1d98d8ec84685c65959964147718"}}}}
{"actor":{"display_login":"viroulep"}}