{"action":"created","comment":{"url":"https://api.github.com/repos/zendesk/kasket/pulls/comments/48916884","id":48916884,"diff_hunk":"@@ -1,3 +1,5 @@\n+require 'set'","path":"lib/kasket/write_mixin.rb","position":null,"original_position":1,"commit_id":"aaa43325f722ce7f96e36b87973f1b4bb5a35ee6","original_commit_id":"b13a88eba1cbede6953058e217e89974cf1ab1a1","user":{"login":"steved","id":13248,"avatar_url":"https://avatars.githubusercontent.com/u/13248?v=3","gravatar_id":"","url":"https://api.github.com/users/steved","html_url":"https://github.com/steved","followers_url":"https://api.github.com/users/steved/followers","following_url":"https://api.github.com/users/steved/following{/other_user}","gists_url":"https://api.github.com/users/steved/gists{/gist_id}","starred_url":"https://api.github.com/users/steved/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/steved/subscriptions","organizations_url":"https://api.github.com/users/steved/orgs","repos_url":"https://api.github.com/users/steved/repos","events_url":"https://api.github.com/users/steved/events{/privacy}","received_events_url":"https://api.github.com/users/steved/received_events","type":"User","site_admin":false},"body":"this is leftover","created_at":"2016-01-06T00:53:19Z","updated_at":"2016-01-06T00:53:19Z","html_url":"https://github.com/zendesk/kasket/pull/31#discussion_r48916884","pull_request_url":"https://api.github.com/repos/zendesk/kasket/pulls/31","_links":{"self":{"href":"https://api.github.com/repos/zendesk/kasket/pulls/comments/48916884"},"html":{"href":"https://github.com/zendesk/kasket/pull/31#discussion_r48916884"},"pull_request":{"href":"https://api.github.com/repos/zendesk/kasket/pulls/31"}}},"pull_request":{"url":"https://api.github.com/repos/zendesk/kasket/pulls/31","id":55135448,"html_url":"https://github.com/zendesk/kasket/pull/31","diff_url":"https://github.com/zendesk/kasket/pull/31.diff","patch_url":"https://github.com/zendesk/kasket/pull/31.patch","issue_url":"https://api.github.com/repos/zendesk/kasket/issues/31","number":31,"state":"open","locked":false,"title":"Prevent stale cache reads between after_save and after_commit, Take Two","user":{"login":"ggrossman","id":5636481,"avatar_url":"https://avatars.githubusercontent.com/u/5636481?v=3","gravatar_id":"","url":"https://api.github.com/users/ggrossman","html_url":"https://github.com/ggrossman","followers_url":"https://api.github.com/users/ggrossman/followers","following_url":"https://api.github.com/users/ggrossman/following{/other_user}","gists_url":"https://api.github.com/users/ggrossman/gists{/gist_id}","starred_url":"https://api.github.com/users/ggrossman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ggrossman/subscriptions","organizations_url":"https://api.github.com/users/ggrossman/orgs","repos_url":"https://api.github.com/users/ggrossman/repos","events_url":"https://api.github.com/users/ggrossman/events{/privacy}","received_events_url":"https://api.github.com/users/ggrossman/received_events","type":"User","site_admin":false},"body":"This is a new approach to solving the problem in https://github.com/zendesk/kasket/pull/30\r\n\r\nAfter an object has been saved, but before it has been committed, the thread that saved the object might query it again.\r\n\r\nIf it does, it currently could read the version in the Kasket cache, which is not yet updated or deleted since we've moved the cache invalidation behavior from `after_save` to `after_commit`.\r\n\r\nThis fixes that problem by keeping a thread-local hash map of objects that have been saved but not committed by the thread. We filter the results of Kasket cache reads to substitute the pending saved object for the stale cached object. This way, the calling thread will see the same view of data in the cache as it does in the database. When we commit or rollback, we can clear the pending records hash.\r\n\r\nNote: Kasket disables itself for the current thread when `transaction` is invoked on a Kasket-enabled model. It doesn't, however, disable itself if a transaction is started on a non-Kasket model, or using `ActiveRecord::Base.transaction`. Yet another solution would be to disable Kasket more globally when any AR transaction is in progress, but that would increase cache miss rates.\r\n\r\n/cc @zendesk/archer @zendesk/sustaining @staugaard @steved @grosser \r\n","created_at":"2016-01-05T19:59:09Z","updated_at":"2016-01-06T00:53:19Z","closed_at":null,"merged_at":null,"merge_commit_sha":"9501ab3fe2253367b8a96383efdf8ed9338b7ead","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/zendesk/kasket/pulls/31/commits","review_comments_url":"https://api.github.com/repos/zendesk/kasket/pulls/31/comments","review_comment_url":"https://api.github.com/repos/zendesk/kasket/pulls/comments{/number}","comments_url":"https://api.github.com/repos/zendesk/kasket/issues/31/comments","statuses_url":"https://api.github.com/repos/zendesk/kasket/statuses/aaa43325f722ce7f96e36b87973f1b4bb5a35ee6","head":{"label":"zendesk:ggrossman/pending_records","ref":"ggrossman/pending_records","sha":"aaa43325f722ce7f96e36b87973f1b4bb5a35ee6","user":{"login":"zendesk","id":11525,"avatar_url":"https://avatars.githubusercontent.com/u/11525?v=3","gravatar_id":"","url":"https://api.github.com/users/zendesk","html_url":"https://github.com/zendesk","followers_url":"https://api.github.com/users/zendesk/followers","following_url":"https://api.github.com/users/zendesk/following{/other_user}","gists_url":"https://api.github.com/users/zendesk/gists{/gist_id}","starred_url":"https://api.github.com/users/zendesk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zendesk/subscriptions","organizations_url":"https://api.github.com/users/zendesk/orgs","repos_url":"https://api.github.com/users/zendesk/repos","events_url":"https://api.github.com/users/zendesk/events{/privacy}","received_events_url":"https://api.github.com/users/zendesk/received_events","type":"Organization","site_admin":false},"repo":{"id":8302270,"name":"kasket","full_name":"zendesk/kasket","owner":{"login":"zendesk","id":11525,"avatar_url":"https://avatars.githubusercontent.com/u/11525?v=3","gravatar_id":"","url":"https://api.github.com/users/zendesk","html_url":"https://github.com/zendesk","followers_url":"https://api.github.com/users/zendesk/followers","following_url":"https://api.github.com/users/zendesk/following{/other_user}","gists_url":"https://api.github.com/users/zendesk/gists{/gist_id}","starred_url":"https://api.github.com/users/zendesk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zendesk/subscriptions","organizations_url":"https://api.github.com/users/zendesk/orgs","repos_url":"https://api.github.com/users/zendesk/repos","events_url":"https://api.github.com/users/zendesk/events{/privacy}","received_events_url":"https://api.github.com/users/zendesk/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/zendesk/kasket","description":"A caching layer for ActiveRecord. Puts a cap on your queries!","fork":true,"url":"https://api.github.com/repos/zendesk/kasket","forks_url":"https://api.github.com/repos/zendesk/kasket/forks","keys_url":"https://api.github.com/repos/zendesk/kasket/keys{/key_id}","collaborators_url":"https://api.github.com/repos/zendesk/kasket/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/zendesk/kasket/teams","hooks_url":"https://api.github.com/repos/zendesk/kasket/hooks","issue_events_url":"https://api.github.com/repos/zendesk/kasket/issues/events{/number}","events_url":"https://api.github.com/repos/zendesk/kasket/events","assignees_url":"https://api.github.com/repos/zendesk/kasket/assignees{/user}","branches_url":"https://api.github.com/repos/zendesk/kasket/branches{/branch}","tags_url":"https://api.github.com/repos/zendesk/kasket/tags","blobs_url":"https://api.github.com/repos/zendesk/kasket/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/zendesk/kasket/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/zendesk/kasket/git/refs{/sha}","trees_url":"https://api.github.com/repos/zendesk/kasket/git/trees{/sha}","statuses_url":"https://api.github.com/repos/zendesk/kasket/statuses/{sha}","languages_url":"https://api.github.com/repos/zendesk/kasket/languages","stargazers_url":"https://api.github.com/repos/zendesk/kasket/stargazers","contributors_url":"https://api.github.com/repos/zendesk/kasket/contributors","subscribers_url":"https://api.github.com/repos/zendesk/kasket/subscribers","subscription_url":"https://api.github.com/repos/zendesk/kasket/subscription","commits_url":"https://api.github.com/repos/zendesk/kasket/commits{/sha}","git_commits_url":"https://api.github.com/repos/zendesk/kasket/git/commits{/sha}","comments_url":"https://api.github.com/repos/zendesk/kasket/comments{/number}","issue_comment_url":"https://api.github.com/repos/zendesk/kasket/issues/comments{/number}","contents_url":"https://api.github.com/repos/zendesk/kasket/contents/{+path}","compare_url":"https://api.github.com/repos/zendesk/kasket/compare/{base}...{head}","merges_url":"https://api.github.com/repos/zendesk/kasket/merges","archive_url":"https://api.github.com/repos/zendesk/kasket/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/zendesk/kasket/downloads","issues_url":"https://api.github.com/repos/zendesk/kasket/issues{/number}","pulls_url":"https://api.github.com/repos/zendesk/kasket/pulls{/number}","milestones_url":"https://api.github.com/repos/zendesk/kasket/milestones{/number}","notifications_url":"https://api.github.com/repos/zendesk/kasket/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/zendesk/kasket/labels{/name}","releases_url":"https://api.github.com/repos/zendesk/kasket/releases{/id}","created_at":"2013-02-19T23:57:02Z","updated_at":"2015-12-21T13:00:37Z","pushed_at":"2016-01-05T20:17:56Z","git_url":"git://github.com/zendesk/kasket.git","ssh_url":"git@github.com:zendesk/kasket.git","clone_url":"https://github.com/zendesk/kasket.git","svn_url":"https://github.com/zendesk/kasket","homepage":"","size":538,"stargazers_count":13,"watchers_count":13,"language":"Ruby","has_issues":false,"has_downloads":false,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":2,"forks":0,"open_issues":2,"watchers":13,"default_branch":"master"}},"base":{"label":"zendesk:master","ref":"master","sha":"661ca9cad0b2143146f7b9b95781f101c4101f79","user":{"login":"zendesk","id":11525,"avatar_url":"https://avatars.githubusercontent.com/u/11525?v=3","gravatar_id":"","url":"https://api.github.com/users/zendesk","html_url":"https://github.com/zendesk","followers_url":"https://api.github.com/users/zendesk/followers","following_url":"https://api.github.com/users/zendesk/following{/other_user}","gists_url":"https://api.github.com/users/zendesk/gists{/gist_id}","starred_url":"https://api.github.com/users/zendesk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zendesk/subscriptions","organizations_url":"https://api.github.com/users/zendesk/orgs","repos_url":"https://api.github.com/users/zendesk/repos","events_url":"https://api.github.com/users/zendesk/events{/privacy}","received_events_url":"https://api.github.com/users/zendesk/received_events","type":"Organization","site_admin":false},"repo":{"id":8302270,"name":"kasket","full_name":"zendesk/kasket","owner":{"login":"zendesk","id":11525,"avatar_url":"https://avatars.githubusercontent.com/u/11525?v=3","gravatar_id":"","url":"https://api.github.com/users/zendesk","html_url":"https://github.com/zendesk","followers_url":"https://api.github.com/users/zendesk/followers","following_url":"https://api.github.com/users/zendesk/following{/other_user}","gists_url":"https://api.github.com/users/zendesk/gists{/gist_id}","starred_url":"https://api.github.com/users/zendesk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zendesk/subscriptions","organizations_url":"https://api.github.com/users/zendesk/orgs","repos_url":"https://api.github.com/users/zendesk/repos","events_url":"https://api.github.com/users/zendesk/events{/privacy}","received_events_url":"https://api.github.com/users/zendesk/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/zendesk/kasket","description":"A caching layer for ActiveRecord. Puts a cap on your queries!","fork":true,"url":"https://api.github.com/repos/zendesk/kasket","forks_url":"https://api.github.com/repos/zendesk/kasket/forks","keys_url":"https://api.github.com/repos/zendesk/kasket/keys{/key_id}","collaborators_url":"https://api.github.com/repos/zendesk/kasket/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/zendesk/kasket/teams","hooks_url":"https://api.github.com/repos/zendesk/kasket/hooks","issue_events_url":"https://api.github.com/repos/zendesk/kasket/issues/events{/number}","events_url":"https://api.github.com/repos/zendesk/kasket/events","assignees_url":"https://api.github.com/repos/zendesk/kasket/assignees{/user}","branches_url":"https://api.github.com/repos/zendesk/kasket/branches{/branch}","tags_url":"https://api.github.com/repos/zendesk/kasket/tags","blobs_url":"https://api.github.com/repos/zendesk/kasket/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/zendesk/kasket/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/zendesk/kasket/git/refs{/sha}","trees_url":"https://api.github.com/repos/zendesk/kasket/git/trees{/sha}","statuses_url":"https://api.github.com/repos/zendesk/kasket/statuses/{sha}","languages_url":"https://api.github.com/repos/zendesk/kasket/languages","stargazers_url":"https://api.github.com/repos/zendesk/kasket/stargazers","contributors_url":"https://api.github.com/repos/zendesk/kasket/contributors","subscribers_url":"https://api.github.com/repos/zendesk/kasket/subscribers","subscription_url":"https://api.github.com/repos/zendesk/kasket/subscription","commits_url":"https://api.github.com/repos/zendesk/kasket/commits{/sha}","git_commits_url":"https://api.github.com/repos/zendesk/kasket/git/commits{/sha}","comments_url":"https://api.github.com/repos/zendesk/kasket/comments{/number}","issue_comment_url":"https://api.github.com/repos/zendesk/kasket/issues/comments{/number}","contents_url":"https://api.github.com/repos/zendesk/kasket/contents/{+path}","compare_url":"https://api.github.com/repos/zendesk/kasket/compare/{base}...{head}","merges_url":"https://api.github.com/repos/zendesk/kasket/merges","archive_url":"https://api.github.com/repos/zendesk/kasket/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/zendesk/kasket/downloads","issues_url":"https://api.github.com/repos/zendesk/kasket/issues{/number}","pulls_url":"https://api.github.com/repos/zendesk/kasket/pulls{/number}","milestones_url":"https://api.github.com/repos/zendesk/kasket/milestones{/number}","notifications_url":"https://api.github.com/repos/zendesk/kasket/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/zendesk/kasket/labels{/name}","releases_url":"https://api.github.com/repos/zendesk/kasket/releases{/id}","created_at":"2013-02-19T23:57:02Z","updated_at":"2015-12-21T13:00:37Z","pushed_at":"2016-01-05T20:17:56Z","git_url":"git://github.com/zendesk/kasket.git","ssh_url":"git@github.com:zendesk/kasket.git","clone_url":"https://github.com/zendesk/kasket.git","svn_url":"https://github.com/zendesk/kasket","homepage":"","size":538,"stargazers_count":13,"watchers_count":13,"language":"Ruby","has_issues":false,"has_downloads":false,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":2,"forks":0,"open_issues":2,"watchers":13,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/zendesk/kasket/pulls/31"},"html":{"href":"https://github.com/zendesk/kasket/pull/31"},"issue":{"href":"https://api.github.com/repos/zendesk/kasket/issues/31"},"comments":{"href":"https://api.github.com/repos/zendesk/kasket/issues/31/comments"},"review_comments":{"href":"https://api.github.com/repos/zendesk/kasket/pulls/31/comments"},"review_comment":{"href":"https://api.github.com/repos/zendesk/kasket/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/zendesk/kasket/pulls/31/commits"},"statuses":{"href":"https://api.github.com/repos/zendesk/kasket/statuses/aaa43325f722ce7f96e36b87973f1b4bb5a35ee6"}}}}