{"action":"created","comment":{"url":"https://api.github.com/repos/rubyist-connect/rubyist-connect/pulls/comments/23122706","id":23122706,"diff_hunk":"@@ -4,6 +4,6 @@ def index\n     if user_signed_in?\n       redirect_to users_path\n     end\n-    @users = @q.result.active.page params[:page]\n+    @users = @q.result.active.sample(Settings.top_page_users_count)","path":"app/controllers/top_controller.rb","position":5,"original_position":5,"commit_id":"dd2ff52b696041f5c0e41753ee526c79807f131c","original_commit_id":"dd2ff52b696041f5c0e41753ee526c79807f131c","user":{"login":"JunichiIto","id":1148320,"avatar_url":"https://avatars.githubusercontent.com/u/1148320?v=3","gravatar_id":"","url":"https://api.github.com/users/JunichiIto","html_url":"https://github.com/JunichiIto","followers_url":"https://api.github.com/users/JunichiIto/followers","following_url":"https://api.github.com/users/JunichiIto/following{/other_user}","gists_url":"https://api.github.com/users/JunichiIto/gists{/gist_id}","starred_url":"https://api.github.com/users/JunichiIto/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JunichiIto/subscriptions","organizations_url":"https://api.github.com/users/JunichiIto/orgs","repos_url":"https://api.github.com/users/JunichiIto/repos","events_url":"https://api.github.com/users/JunichiIto/events{/privacy}","received_events_url":"https://api.github.com/users/JunichiIto/received_events","type":"User","site_admin":false},"body":"`sample` を使うと全てのレコードをいったんメモリに格納することになります。\r\nユーザーの件数が少ないうちはいいですが、ユーザーが増えるとサーバーの負荷を上がるので避けた方がいいです。\r\n\r\n調べてみたら、Postgresでは ORDER BY RANDOM() という指定ができるようです。\r\n\r\nhttp://www.programming-magic.com/20080110002650/\r\n\r\n`User.active.order('RANDOM()').limit(Settings.top_page_users_count)` とやると、負荷を上げずに同じ結果を得られます。","created_at":"2015-01-17T04:18:43Z","updated_at":"2015-01-17T04:18:43Z","html_url":"https://github.com/rubyist-connect/rubyist-connect/pull/202#discussion_r23122706","pull_request_url":"https://api.github.com/repos/rubyist-connect/rubyist-connect/pulls/202","_links":{"self":{"href":"https://api.github.com/repos/rubyist-connect/rubyist-connect/pulls/comments/23122706"},"html":{"href":"https://github.com/rubyist-connect/rubyist-connect/pull/202#discussion_r23122706"},"pull_request":{"href":"https://api.github.com/repos/rubyist-connect/rubyist-connect/pulls/202"}}},"pull_request":{"url":"https://api.github.com/repos/rubyist-connect/rubyist-connect/pulls/202","id":27546334,"html_url":"https://github.com/rubyist-connect/rubyist-connect/pull/202","diff_url":"https://github.com/rubyist-connect/rubyist-connect/pull/202.diff","patch_url":"https://github.com/rubyist-connect/rubyist-connect/pull/202.patch","issue_url":"https://api.github.com/repos/rubyist-connect/rubyist-connect/issues/202","number":202,"state":"open","locked":false,"title":"show random users on top page #160","user":{"login":"t-oginogin","id":1531739,"avatar_url":"https://avatars.githubusercontent.com/u/1531739?v=3","gravatar_id":"","url":"https://api.github.com/users/t-oginogin","html_url":"https://github.com/t-oginogin","followers_url":"https://api.github.com/users/t-oginogin/followers","following_url":"https://api.github.com/users/t-oginogin/following{/other_user}","gists_url":"https://api.github.com/users/t-oginogin/gists{/gist_id}","starred_url":"https://api.github.com/users/t-oginogin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/t-oginogin/subscriptions","organizations_url":"https://api.github.com/users/t-oginogin/orgs","repos_url":"https://api.github.com/users/t-oginogin/repos","events_url":"https://api.github.com/users/t-oginogin/events{/privacy}","received_events_url":"https://api.github.com/users/t-oginogin/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-01-16T23:58:15Z","updated_at":"2015-01-17T04:18:43Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f138165570511b538334421f6261ae3fa69457eb","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/rubyist-connect/rubyist-connect/pulls/202/commits","review_comments_url":"https://api.github.com/repos/rubyist-connect/rubyist-connect/pulls/202/comments","review_comment_url":"https://api.github.com/repos/rubyist-connect/rubyist-connect/pulls/comments/{number}","comments_url":"https://api.github.com/repos/rubyist-connect/rubyist-connect/issues/202/comments","statuses_url":"https://api.github.com/repos/rubyist-connect/rubyist-connect/statuses/dd2ff52b696041f5c0e41753ee526c79807f131c","head":{"label":"t-oginogin:issue_160","ref":"issue_160","sha":"dd2ff52b696041f5c0e41753ee526c79807f131c","user":{"login":"t-oginogin","id":1531739,"avatar_url":"https://avatars.githubusercontent.com/u/1531739?v=3","gravatar_id":"","url":"https://api.github.com/users/t-oginogin","html_url":"https://github.com/t-oginogin","followers_url":"https://api.github.com/users/t-oginogin/followers","following_url":"https://api.github.com/users/t-oginogin/following{/other_user}","gists_url":"https://api.github.com/users/t-oginogin/gists{/gist_id}","starred_url":"https://api.github.com/users/t-oginogin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/t-oginogin/subscriptions","organizations_url":"https://api.github.com/users/t-oginogin/orgs","repos_url":"https://api.github.com/users/t-oginogin/repos","events_url":"https://api.github.com/users/t-oginogin/events{/privacy}","received_events_url":"https://api.github.com/users/t-oginogin/received_events","type":"User","site_admin":false},"repo":{"id":28448338,"name":"rubyist-connect","full_name":"t-oginogin/rubyist-connect","owner":{"login":"t-oginogin","id":1531739,"avatar_url":"https://avatars.githubusercontent.com/u/1531739?v=3","gravatar_id":"","url":"https://api.github.com/users/t-oginogin","html_url":"https://github.com/t-oginogin","followers_url":"https://api.github.com/users/t-oginogin/followers","following_url":"https://api.github.com/users/t-oginogin/following{/other_user}","gists_url":"https://api.github.com/users/t-oginogin/gists{/gist_id}","starred_url":"https://api.github.com/users/t-oginogin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/t-oginogin/subscriptions","organizations_url":"https://api.github.com/users/t-oginogin/orgs","repos_url":"https://api.github.com/users/t-oginogin/repos","events_url":"https://api.github.com/users/t-oginogin/events{/privacy}","received_events_url":"https://api.github.com/users/t-oginogin/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/t-oginogin/rubyist-connect","description":"","fork":true,"url":"https://api.github.com/repos/t-oginogin/rubyist-connect","forks_url":"https://api.github.com/repos/t-oginogin/rubyist-connect/forks","keys_url":"https://api.github.com/repos/t-oginogin/rubyist-connect/keys{/key_id}","collaborators_url":"https://api.github.com/repos/t-oginogin/rubyist-connect/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/t-oginogin/rubyist-connect/teams","hooks_url":"https://api.github.com/repos/t-oginogin/rubyist-connect/hooks","issue_events_url":"https://api.github.com/repos/t-oginogin/rubyist-connect/issues/events{/number}","events_url":"https://api.github.com/repos/t-oginogin/rubyist-connect/events","assignees_url":"https://api.github.com/repos/t-oginogin/rubyist-connect/assignees{/user}","branches_url":"https://api.github.com/repos/t-oginogin/rubyist-connect/branches{/branch}","tags_url":"https://api.github.com/repos/t-oginogin/rubyist-connect/tags","blobs_url":"https://api.github.com/repos/t-oginogin/rubyist-connect/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/t-oginogin/rubyist-connect/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/t-oginogin/rubyist-connect/git/refs{/sha}","trees_url":"https://api.github.com/repos/t-oginogin/rubyist-connect/git/trees{/sha}","statuses_url":"https://api.github.com/repos/t-oginogin/rubyist-connect/statuses/{sha}","languages_url":"https://api.github.com/repos/t-oginogin/rubyist-connect/languages","stargazers_url":"https://api.github.com/repos/t-oginogin/rubyist-connect/stargazers","contributors_url":"https://api.github.com/repos/t-oginogin/rubyist-connect/contributors","subscribers_url":"https://api.github.com/repos/t-oginogin/rubyist-connect/subscribers","subscription_url":"https://api.github.com/repos/t-oginogin/rubyist-connect/subscription","commits_url":"https://api.github.com/repos/t-oginogin/rubyist-connect/commits{/sha}","git_commits_url":"https://api.github.com/repos/t-oginogin/rubyist-connect/git/commits{/sha}","comments_url":"https://api.github.com/repos/t-oginogin/rubyist-connect/comments{/number}","issue_comment_url":"https://api.github.com/repos/t-oginogin/rubyist-connect/issues/comments/{number}","contents_url":"https://api.github.com/repos/t-oginogin/rubyist-connect/contents/{+path}","compare_url":"https://api.github.com/repos/t-oginogin/rubyist-connect/compare/{base}...{head}","merges_url":"https://api.github.com/repos/t-oginogin/rubyist-connect/merges","archive_url":"https://api.github.com/repos/t-oginogin/rubyist-connect/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/t-oginogin/rubyist-connect/downloads","issues_url":"https://api.github.com/repos/t-oginogin/rubyist-connect/issues{/number}","pulls_url":"https://api.github.com/repos/t-oginogin/rubyist-connect/pulls{/number}","milestones_url":"https://api.github.com/repos/t-oginogin/rubyist-connect/milestones{/number}","notifications_url":"https://api.github.com/repos/t-oginogin/rubyist-connect/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/t-oginogin/rubyist-connect/labels{/name}","releases_url":"https://api.github.com/repos/t-oginogin/rubyist-connect/releases{/id}","created_at":"2014-12-24T12:30:23Z","updated_at":"2015-01-08T23:51:04Z","pushed_at":"2015-01-16T23:57:38Z","git_url":"git://github.com/t-oginogin/rubyist-connect.git","ssh_url":"git@github.com:t-oginogin/rubyist-connect.git","clone_url":"https://github.com/t-oginogin/rubyist-connect.git","svn_url":"https://github.com/t-oginogin/rubyist-connect","homepage":null,"size":365,"stargazers_count":0,"watchers_count":0,"language":"Ruby","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":"rubyist-connect:master","ref":"master","sha":"7ae60174d8826ab5e3d19316bec6dab5a0049763","user":{"login":"rubyist-connect","id":10484798,"avatar_url":"https://avatars.githubusercontent.com/u/10484798?v=3","gravatar_id":"","url":"https://api.github.com/users/rubyist-connect","html_url":"https://github.com/rubyist-connect","followers_url":"https://api.github.com/users/rubyist-connect/followers","following_url":"https://api.github.com/users/rubyist-connect/following{/other_user}","gists_url":"https://api.github.com/users/rubyist-connect/gists{/gist_id}","starred_url":"https://api.github.com/users/rubyist-connect/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rubyist-connect/subscriptions","organizations_url":"https://api.github.com/users/rubyist-connect/orgs","repos_url":"https://api.github.com/users/rubyist-connect/repos","events_url":"https://api.github.com/users/rubyist-connect/events{/privacy}","received_events_url":"https://api.github.com/users/rubyist-connect/received_events","type":"Organization","site_admin":false},"repo":{"id":24780019,"name":"rubyist-connect","full_name":"rubyist-connect/rubyist-connect","owner":{"login":"rubyist-connect","id":10484798,"avatar_url":"https://avatars.githubusercontent.com/u/10484798?v=3","gravatar_id":"","url":"https://api.github.com/users/rubyist-connect","html_url":"https://github.com/rubyist-connect","followers_url":"https://api.github.com/users/rubyist-connect/followers","following_url":"https://api.github.com/users/rubyist-connect/following{/other_user}","gists_url":"https://api.github.com/users/rubyist-connect/gists{/gist_id}","starred_url":"https://api.github.com/users/rubyist-connect/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rubyist-connect/subscriptions","organizations_url":"https://api.github.com/users/rubyist-connect/orgs","repos_url":"https://api.github.com/users/rubyist-connect/repos","events_url":"https://api.github.com/users/rubyist-connect/events{/privacy}","received_events_url":"https://api.github.com/users/rubyist-connect/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/rubyist-connect/rubyist-connect","description":"Rubyist をつなぐ WEBサービスです。","fork":false,"url":"https://api.github.com/repos/rubyist-connect/rubyist-connect","forks_url":"https://api.github.com/repos/rubyist-connect/rubyist-connect/forks","keys_url":"https://api.github.com/repos/rubyist-connect/rubyist-connect/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rubyist-connect/rubyist-connect/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rubyist-connect/rubyist-connect/teams","hooks_url":"https://api.github.com/repos/rubyist-connect/rubyist-connect/hooks","issue_events_url":"https://api.github.com/repos/rubyist-connect/rubyist-connect/issues/events{/number}","events_url":"https://api.github.com/repos/rubyist-connect/rubyist-connect/events","assignees_url":"https://api.github.com/repos/rubyist-connect/rubyist-connect/assignees{/user}","branches_url":"https://api.github.com/repos/rubyist-connect/rubyist-connect/branches{/branch}","tags_url":"https://api.github.com/repos/rubyist-connect/rubyist-connect/tags","blobs_url":"https://api.github.com/repos/rubyist-connect/rubyist-connect/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rubyist-connect/rubyist-connect/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rubyist-connect/rubyist-connect/git/refs{/sha}","trees_url":"https://api.github.com/repos/rubyist-connect/rubyist-connect/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rubyist-connect/rubyist-connect/statuses/{sha}","languages_url":"https://api.github.com/repos/rubyist-connect/rubyist-connect/languages","stargazers_url":"https://api.github.com/repos/rubyist-connect/rubyist-connect/stargazers","contributors_url":"https://api.github.com/repos/rubyist-connect/rubyist-connect/contributors","subscribers_url":"https://api.github.com/repos/rubyist-connect/rubyist-connect/subscribers","subscription_url":"https://api.github.com/repos/rubyist-connect/rubyist-connect/subscription","commits_url":"https://api.github.com/repos/rubyist-connect/rubyist-connect/commits{/sha}","git_commits_url":"https://api.github.com/repos/rubyist-connect/rubyist-connect/git/commits{/sha}","comments_url":"https://api.github.com/repos/rubyist-connect/rubyist-connect/comments{/number}","issue_comment_url":"https://api.github.com/repos/rubyist-connect/rubyist-connect/issues/comments/{number}","contents_url":"https://api.github.com/repos/rubyist-connect/rubyist-connect/contents/{+path}","compare_url":"https://api.github.com/repos/rubyist-connect/rubyist-connect/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rubyist-connect/rubyist-connect/merges","archive_url":"https://api.github.com/repos/rubyist-connect/rubyist-connect/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rubyist-connect/rubyist-connect/downloads","issues_url":"https://api.github.com/repos/rubyist-connect/rubyist-connect/issues{/number}","pulls_url":"https://api.github.com/repos/rubyist-connect/rubyist-connect/pulls{/number}","milestones_url":"https://api.github.com/repos/rubyist-connect/rubyist-connect/milestones{/number}","notifications_url":"https://api.github.com/repos/rubyist-connect/rubyist-connect/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rubyist-connect/rubyist-connect/labels{/name}","releases_url":"https://api.github.com/repos/rubyist-connect/rubyist-connect/releases{/id}","created_at":"2014-10-04T02:36:46Z","updated_at":"2015-01-16T16:28:34Z","pushed_at":"2015-01-16T16:28:34Z","git_url":"git://github.com/rubyist-connect/rubyist-connect.git","ssh_url":"git@github.com:rubyist-connect/rubyist-connect.git","clone_url":"https://github.com/rubyist-connect/rubyist-connect.git","svn_url":"https://github.com/rubyist-connect/rubyist-connect","homepage":"http://rubyist.co/","size":1843,"stargazers_count":3,"watchers_count":3,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":20,"mirror_url":null,"open_issues_count":42,"forks":20,"open_issues":42,"watchers":3,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/rubyist-connect/rubyist-connect/pulls/202"},"html":{"href":"https://github.com/rubyist-connect/rubyist-connect/pull/202"},"issue":{"href":"https://api.github.com/repos/rubyist-connect/rubyist-connect/issues/202"},"comments":{"href":"https://api.github.com/repos/rubyist-connect/rubyist-connect/issues/202/comments"},"review_comments":{"href":"https://api.github.com/repos/rubyist-connect/rubyist-connect/pulls/202/comments"},"review_comment":{"href":"https://api.github.com/repos/rubyist-connect/rubyist-connect/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/rubyist-connect/rubyist-connect/pulls/202/commits"},"statuses":{"href":"https://api.github.com/repos/rubyist-connect/rubyist-connect/statuses/dd2ff52b696041f5c0e41753ee526c79807f131c"}}}}