{"action":"created","comment":{"url":"https://api.github.com/repos/ledermann/unread/pulls/comments/75589981","id":75589981,"diff_hunk":"@@ -266,6 +266,17 @@\n       expect(@email2.unread?(@reader)).to be_falsey\n     end\n \n+    it \"should mark the rest as read when the first record is not unique\" do\n+      Email.mark_as_read! [ @email1 ], for: @reader\n+\n+      allow(@email1).to receive_message_chain(\"read_marks.build\").and_return(@email1.read_marks.build)\n+      allow(@email1).to receive_message_chain(\"read_marks.where\").and_return([])","path":"spec/unread/readable_spec.rb","position":8,"original_position":8,"commit_id":"f1d9e457b136c7307705b18f5d579e0d4ffd5365","original_commit_id":"f1d9e457b136c7307705b18f5d579e0d4ffd5365","user":{"login":"allenwq","id":4983239,"avatar_url":"https://avatars.githubusercontent.com/u/4983239?v=3","gravatar_id":"","url":"https://api.github.com/users/allenwq","html_url":"https://github.com/allenwq","followers_url":"https://api.github.com/users/allenwq/followers","following_url":"https://api.github.com/users/allenwq/following{/other_user}","gists_url":"https://api.github.com/users/allenwq/gists{/gist_id}","starred_url":"https://api.github.com/users/allenwq/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/allenwq/subscriptions","organizations_url":"https://api.github.com/users/allenwq/orgs","repos_url":"https://api.github.com/users/allenwq/repos","events_url":"https://api.github.com/users/allenwq/events{/privacy}","received_events_url":"https://api.github.com/users/allenwq/received_events","type":"User","site_admin":false},"body":"I think database level unique constraint guarantees that no duplicate records will be saved. \r\n\r\nIt's very hard to simulate a non-thread safe condition using threads because they are non-deterministic.  Actually, the mocking achieves the same propose and it's deterministic.","created_at":"2016-08-21T07:14:53Z","updated_at":"2016-08-21T07:14:53Z","html_url":"https://github.com/ledermann/unread/pull/78#discussion_r75589981","pull_request_url":"https://api.github.com/repos/ledermann/unread/pulls/78","_links":{"self":{"href":"https://api.github.com/repos/ledermann/unread/pulls/comments/75589981"},"html":{"href":"https://github.com/ledermann/unread/pull/78#discussion_r75589981"},"pull_request":{"href":"https://api.github.com/repos/ledermann/unread/pulls/78"}}},"pull_request":{"url":"https://api.github.com/repos/ledermann/unread/pulls/78","id":82080695,"html_url":"https://github.com/ledermann/unread/pull/78","diff_url":"https://github.com/ledermann/unread/pull/78.diff","patch_url":"https://github.com/ledermann/unread/pull/78.patch","issue_url":"https://api.github.com/repos/ledermann/unread/issues/78","number":78,"state":"open","locked":false,"title":"Add unique constraint to reader and readable","user":{"login":"allenwq","id":4983239,"avatar_url":"https://avatars.githubusercontent.com/u/4983239?v=3","gravatar_id":"","url":"https://api.github.com/users/allenwq","html_url":"https://github.com/allenwq","followers_url":"https://api.github.com/users/allenwq/followers","following_url":"https://api.github.com/users/allenwq/following{/other_user}","gists_url":"https://api.github.com/users/allenwq/gists{/gist_id}","starred_url":"https://api.github.com/users/allenwq/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/allenwq/subscriptions","organizations_url":"https://api.github.com/users/allenwq/orgs","repos_url":"https://api.github.com/users/allenwq/repos","events_url":"https://api.github.com/users/allenwq/events{/privacy}","received_events_url":"https://api.github.com/users/allenwq/received_events","type":"User","site_admin":false},"body":"The readable and reader is not unique before, and `mark_array_as_read` is not thread safe.\r\n\r\nOur production app has lots of duplicates generated under high load. And this further result in duplicated records returned in `.with_readmarks_for(user)`.\r\n\r\nThis PR adds a unique constraint to the table and handle the error.\r\n\r\n\r\nStill working on a test for this.","created_at":"2016-08-20T15:01:15Z","updated_at":"2016-08-21T07:14:53Z","closed_at":null,"merged_at":null,"merge_commit_sha":"8a97a95e706eba70343e3c93bff925c47df6ea4a","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/ledermann/unread/pulls/78/commits","review_comments_url":"https://api.github.com/repos/ledermann/unread/pulls/78/comments","review_comment_url":"https://api.github.com/repos/ledermann/unread/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ledermann/unread/issues/78/comments","statuses_url":"https://api.github.com/repos/ledermann/unread/statuses/f1d9e457b136c7307705b18f5d579e0d4ffd5365","head":{"label":"allenwq:master","ref":"master","sha":"f1d9e457b136c7307705b18f5d579e0d4ffd5365","user":{"login":"allenwq","id":4983239,"avatar_url":"https://avatars.githubusercontent.com/u/4983239?v=3","gravatar_id":"","url":"https://api.github.com/users/allenwq","html_url":"https://github.com/allenwq","followers_url":"https://api.github.com/users/allenwq/followers","following_url":"https://api.github.com/users/allenwq/following{/other_user}","gists_url":"https://api.github.com/users/allenwq/gists{/gist_id}","starred_url":"https://api.github.com/users/allenwq/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/allenwq/subscriptions","organizations_url":"https://api.github.com/users/allenwq/orgs","repos_url":"https://api.github.com/users/allenwq/repos","events_url":"https://api.github.com/users/allenwq/events{/privacy}","received_events_url":"https://api.github.com/users/allenwq/received_events","type":"User","site_admin":false},"repo":{"id":31774421,"name":"unread","full_name":"allenwq/unread","owner":{"login":"allenwq","id":4983239,"avatar_url":"https://avatars.githubusercontent.com/u/4983239?v=3","gravatar_id":"","url":"https://api.github.com/users/allenwq","html_url":"https://github.com/allenwq","followers_url":"https://api.github.com/users/allenwq/followers","following_url":"https://api.github.com/users/allenwq/following{/other_user}","gists_url":"https://api.github.com/users/allenwq/gists{/gist_id}","starred_url":"https://api.github.com/users/allenwq/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/allenwq/subscriptions","organizations_url":"https://api.github.com/users/allenwq/orgs","repos_url":"https://api.github.com/users/allenwq/repos","events_url":"https://api.github.com/users/allenwq/events{/privacy}","received_events_url":"https://api.github.com/users/allenwq/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/allenwq/unread","description":"Ruby gem to manage read/unread status of ActiveRecord objects - and it's fast.","fork":true,"url":"https://api.github.com/repos/allenwq/unread","forks_url":"https://api.github.com/repos/allenwq/unread/forks","keys_url":"https://api.github.com/repos/allenwq/unread/keys{/key_id}","collaborators_url":"https://api.github.com/repos/allenwq/unread/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/allenwq/unread/teams","hooks_url":"https://api.github.com/repos/allenwq/unread/hooks","issue_events_url":"https://api.github.com/repos/allenwq/unread/issues/events{/number}","events_url":"https://api.github.com/repos/allenwq/unread/events","assignees_url":"https://api.github.com/repos/allenwq/unread/assignees{/user}","branches_url":"https://api.github.com/repos/allenwq/unread/branches{/branch}","tags_url":"https://api.github.com/repos/allenwq/unread/tags","blobs_url":"https://api.github.com/repos/allenwq/unread/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/allenwq/unread/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/allenwq/unread/git/refs{/sha}","trees_url":"https://api.github.com/repos/allenwq/unread/git/trees{/sha}","statuses_url":"https://api.github.com/repos/allenwq/unread/statuses/{sha}","languages_url":"https://api.github.com/repos/allenwq/unread/languages","stargazers_url":"https://api.github.com/repos/allenwq/unread/stargazers","contributors_url":"https://api.github.com/repos/allenwq/unread/contributors","subscribers_url":"https://api.github.com/repos/allenwq/unread/subscribers","subscription_url":"https://api.github.com/repos/allenwq/unread/subscription","commits_url":"https://api.github.com/repos/allenwq/unread/commits{/sha}","git_commits_url":"https://api.github.com/repos/allenwq/unread/git/commits{/sha}","comments_url":"https://api.github.com/repos/allenwq/unread/comments{/number}","issue_comment_url":"https://api.github.com/repos/allenwq/unread/issues/comments{/number}","contents_url":"https://api.github.com/repos/allenwq/unread/contents/{+path}","compare_url":"https://api.github.com/repos/allenwq/unread/compare/{base}...{head}","merges_url":"https://api.github.com/repos/allenwq/unread/merges","archive_url":"https://api.github.com/repos/allenwq/unread/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/allenwq/unread/downloads","issues_url":"https://api.github.com/repos/allenwq/unread/issues{/number}","pulls_url":"https://api.github.com/repos/allenwq/unread/pulls{/number}","milestones_url":"https://api.github.com/repos/allenwq/unread/milestones{/number}","notifications_url":"https://api.github.com/repos/allenwq/unread/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/allenwq/unread/labels{/name}","releases_url":"https://api.github.com/repos/allenwq/unread/releases{/id}","deployments_url":"https://api.github.com/repos/allenwq/unread/deployments","created_at":"2015-03-06T15:02:58Z","updated_at":"2016-08-20T14:58:19Z","pushed_at":"2016-08-20T17:33:59Z","git_url":"git://github.com/allenwq/unread.git","ssh_url":"git@github.com:allenwq/unread.git","clone_url":"https://github.com/allenwq/unread.git","svn_url":"https://github.com/allenwq/unread","homepage":"http://github.com/ledermann/unread","size":236,"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":"ledermann:master","ref":"master","sha":"a77b2f9f63874c104f2c0ab3f68b0ab2dbe9402c","user":{"login":"ledermann","id":3557,"avatar_url":"https://avatars.githubusercontent.com/u/3557?v=3","gravatar_id":"","url":"https://api.github.com/users/ledermann","html_url":"https://github.com/ledermann","followers_url":"https://api.github.com/users/ledermann/followers","following_url":"https://api.github.com/users/ledermann/following{/other_user}","gists_url":"https://api.github.com/users/ledermann/gists{/gist_id}","starred_url":"https://api.github.com/users/ledermann/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ledermann/subscriptions","organizations_url":"https://api.github.com/users/ledermann/orgs","repos_url":"https://api.github.com/users/ledermann/repos","events_url":"https://api.github.com/users/ledermann/events{/privacy}","received_events_url":"https://api.github.com/users/ledermann/received_events","type":"User","site_admin":false},"repo":{"id":1011618,"name":"unread","full_name":"ledermann/unread","owner":{"login":"ledermann","id":3557,"avatar_url":"https://avatars.githubusercontent.com/u/3557?v=3","gravatar_id":"","url":"https://api.github.com/users/ledermann","html_url":"https://github.com/ledermann","followers_url":"https://api.github.com/users/ledermann/followers","following_url":"https://api.github.com/users/ledermann/following{/other_user}","gists_url":"https://api.github.com/users/ledermann/gists{/gist_id}","starred_url":"https://api.github.com/users/ledermann/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ledermann/subscriptions","organizations_url":"https://api.github.com/users/ledermann/orgs","repos_url":"https://api.github.com/users/ledermann/repos","events_url":"https://api.github.com/users/ledermann/events{/privacy}","received_events_url":"https://api.github.com/users/ledermann/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ledermann/unread","description":"Handle unread records and mark them as read with Ruby on Rails","fork":false,"url":"https://api.github.com/repos/ledermann/unread","forks_url":"https://api.github.com/repos/ledermann/unread/forks","keys_url":"https://api.github.com/repos/ledermann/unread/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ledermann/unread/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ledermann/unread/teams","hooks_url":"https://api.github.com/repos/ledermann/unread/hooks","issue_events_url":"https://api.github.com/repos/ledermann/unread/issues/events{/number}","events_url":"https://api.github.com/repos/ledermann/unread/events","assignees_url":"https://api.github.com/repos/ledermann/unread/assignees{/user}","branches_url":"https://api.github.com/repos/ledermann/unread/branches{/branch}","tags_url":"https://api.github.com/repos/ledermann/unread/tags","blobs_url":"https://api.github.com/repos/ledermann/unread/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ledermann/unread/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ledermann/unread/git/refs{/sha}","trees_url":"https://api.github.com/repos/ledermann/unread/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ledermann/unread/statuses/{sha}","languages_url":"https://api.github.com/repos/ledermann/unread/languages","stargazers_url":"https://api.github.com/repos/ledermann/unread/stargazers","contributors_url":"https://api.github.com/repos/ledermann/unread/contributors","subscribers_url":"https://api.github.com/repos/ledermann/unread/subscribers","subscription_url":"https://api.github.com/repos/ledermann/unread/subscription","commits_url":"https://api.github.com/repos/ledermann/unread/commits{/sha}","git_commits_url":"https://api.github.com/repos/ledermann/unread/git/commits{/sha}","comments_url":"https://api.github.com/repos/ledermann/unread/comments{/number}","issue_comment_url":"https://api.github.com/repos/ledermann/unread/issues/comments{/number}","contents_url":"https://api.github.com/repos/ledermann/unread/contents/{+path}","compare_url":"https://api.github.com/repos/ledermann/unread/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ledermann/unread/merges","archive_url":"https://api.github.com/repos/ledermann/unread/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ledermann/unread/downloads","issues_url":"https://api.github.com/repos/ledermann/unread/issues{/number}","pulls_url":"https://api.github.com/repos/ledermann/unread/pulls{/number}","milestones_url":"https://api.github.com/repos/ledermann/unread/milestones{/number}","notifications_url":"https://api.github.com/repos/ledermann/unread/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ledermann/unread/labels{/name}","releases_url":"https://api.github.com/repos/ledermann/unread/releases{/id}","deployments_url":"https://api.github.com/repos/ledermann/unread/deployments","created_at":"2010-10-21T09:22:09Z","updated_at":"2016-08-02T08:42:44Z","pushed_at":"2016-08-20T17:34:00Z","git_url":"git://github.com/ledermann/unread.git","ssh_url":"git@github.com:ledermann/unread.git","clone_url":"https://github.com/ledermann/unread.git","svn_url":"https://github.com/ledermann/unread","homepage":"","size":288,"stargazers_count":387,"watchers_count":387,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":60,"mirror_url":null,"open_issues_count":7,"forks":60,"open_issues":7,"watchers":387,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ledermann/unread/pulls/78"},"html":{"href":"https://github.com/ledermann/unread/pull/78"},"issue":{"href":"https://api.github.com/repos/ledermann/unread/issues/78"},"comments":{"href":"https://api.github.com/repos/ledermann/unread/issues/78/comments"},"review_comments":{"href":"https://api.github.com/repos/ledermann/unread/pulls/78/comments"},"review_comment":{"href":"https://api.github.com/repos/ledermann/unread/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ledermann/unread/pulls/78/commits"},"statuses":{"href":"https://api.github.com/repos/ledermann/unread/statuses/f1d9e457b136c7307705b18f5d579e0d4ffd5365"}}}}
{"actor":{"display_login":"allenwq"}}