{"action":"created","comment":{"url":"https://api.github.com/repos/devlocker/backend/pulls/comments/40502358","id":40502358,"diff_hunk":"@@ -0,0 +1,53 @@\n+require \"test_helper\"\n+\n+class TestController < ApiController\n+  skip_before_action :authorize\n+\n+  def index\n+    cache(\"cache_key\") do\n+      [1, 2, 3]\n+    end\n+    head :ok\n+  end\n+\n+  def index2\n+    cache(\"cache_key/#{params[:user_id]}\") do\n+      params[:user_id]\n+    end\n+    head :ok\n+  end\n+end\n+\n+class TestControllerTest < ActionController::TestCase\n+  def setup\n+    Rails.application.routes.draw do\n+      resources :test do\n+        get :index2, on: :collection\n+      end\n+    end\n+  end\n+\n+  def teardown\n+    Rails.application.reload_routes!\n+  end\n+\n+  test \"#cache caches the results of the block to the given cache_key\" do\n+    get :index\n+\n+    assert_equal [1, 2, 3], Rails.cache.fetch(\"cache_key\")\n+  end\n+\n+  test \"#cache won't find the cache when given the wrong cache_key\" do\n+    get :index\n+\n+    assert_nil Rails.cache.fetch(\"wrong_cache_key\")\n+  end\n+\n+  test \"#cache can cache different results for the same action from different users\" do","path":"test/controllers/api_controller_test.rb","position":46,"original_position":46,"commit_id":"fddb9f85850ffb8b03a9af9da0cfdc949e65684c","original_commit_id":"fddb9f85850ffb8b03a9af9da0cfdc949e65684c","user":{"login":"houndci","id":6697940,"avatar_url":"https://avatars.githubusercontent.com/u/6697940?v=3","gravatar_id":"","url":"https://api.github.com/users/houndci","html_url":"https://github.com/houndci","followers_url":"https://api.github.com/users/houndci/followers","following_url":"https://api.github.com/users/houndci/following{/other_user}","gists_url":"https://api.github.com/users/houndci/gists{/gist_id}","starred_url":"https://api.github.com/users/houndci/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/houndci/subscriptions","organizations_url":"https://api.github.com/users/houndci/orgs","repos_url":"https://api.github.com/users/houndci/repos","events_url":"https://api.github.com/users/houndci/events{/privacy}","received_events_url":"https://api.github.com/users/houndci/received_events","type":"User","site_admin":false},"body":"Line is too long. [87/80]","created_at":"2015-09-27T07:40:26Z","updated_at":"2015-09-27T07:40:26Z","html_url":"https://github.com/devlocker/backend/pull/191#discussion_r40502358","pull_request_url":"https://api.github.com/repos/devlocker/backend/pulls/191","_links":{"self":{"href":"https://api.github.com/repos/devlocker/backend/pulls/comments/40502358"},"html":{"href":"https://github.com/devlocker/backend/pull/191#discussion_r40502358"},"pull_request":{"href":"https://api.github.com/repos/devlocker/backend/pulls/191"}}},"pull_request":{"url":"https://api.github.com/repos/devlocker/backend/pulls/191","id":46097097,"html_url":"https://github.com/devlocker/backend/pull/191","diff_url":"https://github.com/devlocker/backend/pull/191.diff","patch_url":"https://github.com/devlocker/backend/pull/191.patch","issue_url":"https://api.github.com/repos/devlocker/backend/issues/191","number":191,"state":"open","locked":false,"title":"Cache all the things","user":{"login":"mcasper","id":6878025,"avatar_url":"https://avatars.githubusercontent.com/u/6878025?v=3","gravatar_id":"","url":"https://api.github.com/users/mcasper","html_url":"https://github.com/mcasper","followers_url":"https://api.github.com/users/mcasper/followers","following_url":"https://api.github.com/users/mcasper/following{/other_user}","gists_url":"https://api.github.com/users/mcasper/gists{/gist_id}","starred_url":"https://api.github.com/users/mcasper/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mcasper/subscriptions","organizations_url":"https://api.github.com/users/mcasper/orgs","repos_url":"https://api.github.com/users/mcasper/repos","events_url":"https://api.github.com/users/mcasper/events{/privacy}","received_events_url":"https://api.github.com/users/mcasper/received_events","type":"User","site_admin":false},"body":"Implement naive caching for most API controllers. Massive speed improvement, takes the Locker#show page (with all the current addons enabled) from an average of 8.5 seconds, to less than a second.\r\n\r\nFor the benchmark\r\n```\r\nrequire \"benchmark\"\r\nrequire \"httparty\"\r\n\r\nBenchmark.bm do |x|\r\n  x.report do\r\n    [\r\n      \"/~/9/basecamp/todolists.json\",\r\n      \"/~/9/jira/items\",\r\n      \"/~/9/todo/items\",\r\n      \"/~/9/github/pull_requests\",\r\n      \"/~/9/google_calendar/items\",\r\n      \"/~/9/basecamp/todos.json?todolist_id=29258913\",\r\n      \"/~/9/basecamp/todos.json?todolist_id=29259339\",\r\n      \"/~/9/basecamp/todos.json?todolist_id=31526383\",\r\n    ].each do |url|\r\n      HTTParty.get(\"http://localhost:3000\" + url, headers: { \"Cookie\" => \"_dev_locker_session=d1RtQ0NoRDFjWXpLUlB5SDk1NktrdzlPYkRERUlpOGRwTWJNcXJ2WWdJSEpyenR2MkJJSitDdHY5a1RXV2RJNFlTMS9GeW9adjJ6b0RYdjNOZ0ViTHgvVVp4bEs1dWM5bU9YQnY0VmZNMmQ1bGVYWXErdityeVF5SDlLZ2pNaWZpR21zMVU0OW1rSjhTZUh6T2lDWXk1ajdNQVByd0I1QjBCWDB4UU1XSTFnPS0tcDFDMTRJbTFZeHcwdW5IMlpHaG45UT09--1a353950ac5d512ced6caec17e62fc4d91ae29d8\" })\r\n    end\r\n  end\r\nend\r\n```\r\n```\r\n# Before\r\n       user     system      total        real\r\n   0.010000   0.000000   0.010000 (  8.396311)\r\n   0.000000   0.000000   0.000000 (  8.493776)\r\n   0.010000   0.000000   0.010000 (  7.786021)\r\n```\r\n```\r\n# After\r\n       user     system      total        real\r\n   0.010000   0.000000   0.010000 (  9.815731)\r\n   0.000000   0.000000   0.000000 (  0.126824)\r\n   0.010000   0.000000   0.010000 (  0.177399)\r\n```","created_at":"2015-09-27T07:40:23Z","updated_at":"2015-09-27T07:40:27Z","closed_at":null,"merged_at":null,"merge_commit_sha":"76490256adbc98715e52bc324038966f856c80f0","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/devlocker/backend/pulls/191/commits","review_comments_url":"https://api.github.com/repos/devlocker/backend/pulls/191/comments","review_comment_url":"https://api.github.com/repos/devlocker/backend/pulls/comments{/number}","comments_url":"https://api.github.com/repos/devlocker/backend/issues/191/comments","statuses_url":"https://api.github.com/repos/devlocker/backend/statuses/fddb9f85850ffb8b03a9af9da0cfdc949e65684c","head":{"label":"devlocker:caching","ref":"caching","sha":"fddb9f85850ffb8b03a9af9da0cfdc949e65684c","user":{"login":"devlocker","id":9755201,"avatar_url":"https://avatars.githubusercontent.com/u/9755201?v=3","gravatar_id":"","url":"https://api.github.com/users/devlocker","html_url":"https://github.com/devlocker","followers_url":"https://api.github.com/users/devlocker/followers","following_url":"https://api.github.com/users/devlocker/following{/other_user}","gists_url":"https://api.github.com/users/devlocker/gists{/gist_id}","starred_url":"https://api.github.com/users/devlocker/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/devlocker/subscriptions","organizations_url":"https://api.github.com/users/devlocker/orgs","repos_url":"https://api.github.com/users/devlocker/repos","events_url":"https://api.github.com/users/devlocker/events{/privacy}","received_events_url":"https://api.github.com/users/devlocker/received_events","type":"Organization","site_admin":false},"repo":{"id":26662265,"name":"backend","full_name":"devlocker/backend","owner":{"login":"devlocker","id":9755201,"avatar_url":"https://avatars.githubusercontent.com/u/9755201?v=3","gravatar_id":"","url":"https://api.github.com/users/devlocker","html_url":"https://github.com/devlocker","followers_url":"https://api.github.com/users/devlocker/followers","following_url":"https://api.github.com/users/devlocker/following{/other_user}","gists_url":"https://api.github.com/users/devlocker/gists{/gist_id}","starred_url":"https://api.github.com/users/devlocker/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/devlocker/subscriptions","organizations_url":"https://api.github.com/users/devlocker/orgs","repos_url":"https://api.github.com/users/devlocker/repos","events_url":"https://api.github.com/users/devlocker/events{/privacy}","received_events_url":"https://api.github.com/users/devlocker/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/devlocker/backend","description":"Ruby/Rails backend for DevLocker","fork":false,"url":"https://api.github.com/repos/devlocker/backend","forks_url":"https://api.github.com/repos/devlocker/backend/forks","keys_url":"https://api.github.com/repos/devlocker/backend/keys{/key_id}","collaborators_url":"https://api.github.com/repos/devlocker/backend/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/devlocker/backend/teams","hooks_url":"https://api.github.com/repos/devlocker/backend/hooks","issue_events_url":"https://api.github.com/repos/devlocker/backend/issues/events{/number}","events_url":"https://api.github.com/repos/devlocker/backend/events","assignees_url":"https://api.github.com/repos/devlocker/backend/assignees{/user}","branches_url":"https://api.github.com/repos/devlocker/backend/branches{/branch}","tags_url":"https://api.github.com/repos/devlocker/backend/tags","blobs_url":"https://api.github.com/repos/devlocker/backend/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/devlocker/backend/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/devlocker/backend/git/refs{/sha}","trees_url":"https://api.github.com/repos/devlocker/backend/git/trees{/sha}","statuses_url":"https://api.github.com/repos/devlocker/backend/statuses/{sha}","languages_url":"https://api.github.com/repos/devlocker/backend/languages","stargazers_url":"https://api.github.com/repos/devlocker/backend/stargazers","contributors_url":"https://api.github.com/repos/devlocker/backend/contributors","subscribers_url":"https://api.github.com/repos/devlocker/backend/subscribers","subscription_url":"https://api.github.com/repos/devlocker/backend/subscription","commits_url":"https://api.github.com/repos/devlocker/backend/commits{/sha}","git_commits_url":"https://api.github.com/repos/devlocker/backend/git/commits{/sha}","comments_url":"https://api.github.com/repos/devlocker/backend/comments{/number}","issue_comment_url":"https://api.github.com/repos/devlocker/backend/issues/comments{/number}","contents_url":"https://api.github.com/repos/devlocker/backend/contents/{+path}","compare_url":"https://api.github.com/repos/devlocker/backend/compare/{base}...{head}","merges_url":"https://api.github.com/repos/devlocker/backend/merges","archive_url":"https://api.github.com/repos/devlocker/backend/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/devlocker/backend/downloads","issues_url":"https://api.github.com/repos/devlocker/backend/issues{/number}","pulls_url":"https://api.github.com/repos/devlocker/backend/pulls{/number}","milestones_url":"https://api.github.com/repos/devlocker/backend/milestones{/number}","notifications_url":"https://api.github.com/repos/devlocker/backend/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/devlocker/backend/labels{/name}","releases_url":"https://api.github.com/repos/devlocker/backend/releases{/id}","created_at":"2014-11-14T23:29:33Z","updated_at":"2015-09-26T22:04:01Z","pushed_at":"2015-09-27T07:40:23Z","git_url":"git://github.com/devlocker/backend.git","ssh_url":"git@github.com:devlocker/backend.git","clone_url":"https://github.com/devlocker/backend.git","svn_url":"https://github.com/devlocker/backend","homepage":"http://devlocker.io","size":3892,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":8,"forks":0,"open_issues":8,"watchers":0,"default_branch":"master"}},"base":{"label":"devlocker:master","ref":"master","sha":"14dde4c67493b0e0fc04a16012b861fe6487edaa","user":{"login":"devlocker","id":9755201,"avatar_url":"https://avatars.githubusercontent.com/u/9755201?v=3","gravatar_id":"","url":"https://api.github.com/users/devlocker","html_url":"https://github.com/devlocker","followers_url":"https://api.github.com/users/devlocker/followers","following_url":"https://api.github.com/users/devlocker/following{/other_user}","gists_url":"https://api.github.com/users/devlocker/gists{/gist_id}","starred_url":"https://api.github.com/users/devlocker/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/devlocker/subscriptions","organizations_url":"https://api.github.com/users/devlocker/orgs","repos_url":"https://api.github.com/users/devlocker/repos","events_url":"https://api.github.com/users/devlocker/events{/privacy}","received_events_url":"https://api.github.com/users/devlocker/received_events","type":"Organization","site_admin":false},"repo":{"id":26662265,"name":"backend","full_name":"devlocker/backend","owner":{"login":"devlocker","id":9755201,"avatar_url":"https://avatars.githubusercontent.com/u/9755201?v=3","gravatar_id":"","url":"https://api.github.com/users/devlocker","html_url":"https://github.com/devlocker","followers_url":"https://api.github.com/users/devlocker/followers","following_url":"https://api.github.com/users/devlocker/following{/other_user}","gists_url":"https://api.github.com/users/devlocker/gists{/gist_id}","starred_url":"https://api.github.com/users/devlocker/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/devlocker/subscriptions","organizations_url":"https://api.github.com/users/devlocker/orgs","repos_url":"https://api.github.com/users/devlocker/repos","events_url":"https://api.github.com/users/devlocker/events{/privacy}","received_events_url":"https://api.github.com/users/devlocker/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/devlocker/backend","description":"Ruby/Rails backend for DevLocker","fork":false,"url":"https://api.github.com/repos/devlocker/backend","forks_url":"https://api.github.com/repos/devlocker/backend/forks","keys_url":"https://api.github.com/repos/devlocker/backend/keys{/key_id}","collaborators_url":"https://api.github.com/repos/devlocker/backend/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/devlocker/backend/teams","hooks_url":"https://api.github.com/repos/devlocker/backend/hooks","issue_events_url":"https://api.github.com/repos/devlocker/backend/issues/events{/number}","events_url":"https://api.github.com/repos/devlocker/backend/events","assignees_url":"https://api.github.com/repos/devlocker/backend/assignees{/user}","branches_url":"https://api.github.com/repos/devlocker/backend/branches{/branch}","tags_url":"https://api.github.com/repos/devlocker/backend/tags","blobs_url":"https://api.github.com/repos/devlocker/backend/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/devlocker/backend/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/devlocker/backend/git/refs{/sha}","trees_url":"https://api.github.com/repos/devlocker/backend/git/trees{/sha}","statuses_url":"https://api.github.com/repos/devlocker/backend/statuses/{sha}","languages_url":"https://api.github.com/repos/devlocker/backend/languages","stargazers_url":"https://api.github.com/repos/devlocker/backend/stargazers","contributors_url":"https://api.github.com/repos/devlocker/backend/contributors","subscribers_url":"https://api.github.com/repos/devlocker/backend/subscribers","subscription_url":"https://api.github.com/repos/devlocker/backend/subscription","commits_url":"https://api.github.com/repos/devlocker/backend/commits{/sha}","git_commits_url":"https://api.github.com/repos/devlocker/backend/git/commits{/sha}","comments_url":"https://api.github.com/repos/devlocker/backend/comments{/number}","issue_comment_url":"https://api.github.com/repos/devlocker/backend/issues/comments{/number}","contents_url":"https://api.github.com/repos/devlocker/backend/contents/{+path}","compare_url":"https://api.github.com/repos/devlocker/backend/compare/{base}...{head}","merges_url":"https://api.github.com/repos/devlocker/backend/merges","archive_url":"https://api.github.com/repos/devlocker/backend/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/devlocker/backend/downloads","issues_url":"https://api.github.com/repos/devlocker/backend/issues{/number}","pulls_url":"https://api.github.com/repos/devlocker/backend/pulls{/number}","milestones_url":"https://api.github.com/repos/devlocker/backend/milestones{/number}","notifications_url":"https://api.github.com/repos/devlocker/backend/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/devlocker/backend/labels{/name}","releases_url":"https://api.github.com/repos/devlocker/backend/releases{/id}","created_at":"2014-11-14T23:29:33Z","updated_at":"2015-09-26T22:04:01Z","pushed_at":"2015-09-27T07:40:23Z","git_url":"git://github.com/devlocker/backend.git","ssh_url":"git@github.com:devlocker/backend.git","clone_url":"https://github.com/devlocker/backend.git","svn_url":"https://github.com/devlocker/backend","homepage":"http://devlocker.io","size":3892,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":8,"forks":0,"open_issues":8,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/devlocker/backend/pulls/191"},"html":{"href":"https://github.com/devlocker/backend/pull/191"},"issue":{"href":"https://api.github.com/repos/devlocker/backend/issues/191"},"comments":{"href":"https://api.github.com/repos/devlocker/backend/issues/191/comments"},"review_comments":{"href":"https://api.github.com/repos/devlocker/backend/pulls/191/comments"},"review_comment":{"href":"https://api.github.com/repos/devlocker/backend/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/devlocker/backend/pulls/191/commits"},"statuses":{"href":"https://api.github.com/repos/devlocker/backend/statuses/fddb9f85850ffb8b03a9af9da0cfdc949e65684c"}}}}