{"action":"created","comment":{"url":"https://api.github.com/repos/alphagov/publishing-api/pulls/comments/54222678","id":54222678,"diff_hunk":"@@ -0,0 +1,41 @@\n+class ContentStorePayloadVersion < ActiveRecord::Base\n+  def self.increment(content_item_id:)\n+    sql = <<-SQL\n+        INSERT INTO content_store_payload_versions (content_item_id)\n+        SELECT #{ content_item_id || \"NULL\" }\n+        WHERE NOT EXISTS(\n+        SELECT *\n+        FROM content_store_payload_versions\n+        WHERE content_item_id #{ content_item_id_sql(content_item_id) });\n+\n+        UPDATE content_store_payload_versions\n+        SET current = COALESCE(current, 0) + 1\n+        WHERE content_item_id #{ content_item_id_sql(content_item_id) }\n+        RETURNING current;\n+      SQL\n+\n+    ContentStorePayloadVersion.connection\n+      .execute(sql)","path":"app/models/content_store_payload_version.rb","position":18,"original_position":18,"commit_id":"bc19b329c33d5215008c7bab768f2e5996f7011e","original_commit_id":"bc19b329c33d5215008c7bab768f2e5996f7011e","user":{"login":"benlovell","id":41963,"avatar_url":"https://avatars.githubusercontent.com/u/41963?v=3","gravatar_id":"","url":"https://api.github.com/users/benlovell","html_url":"https://github.com/benlovell","followers_url":"https://api.github.com/users/benlovell/followers","following_url":"https://api.github.com/users/benlovell/following{/other_user}","gists_url":"https://api.github.com/users/benlovell/gists{/gist_id}","starred_url":"https://api.github.com/users/benlovell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/benlovell/subscriptions","organizations_url":"https://api.github.com/users/benlovell/orgs","repos_url":"https://api.github.com/users/benlovell/repos","events_url":"https://api.github.com/users/benlovell/events{/privacy}","received_events_url":"https://api.github.com/users/benlovell/received_events","type":"User","site_admin":false},"body":"This isn't implicitly transacted. You probably want to ensure this is running in a transaction.","created_at":"2016-02-26T09:46:46Z","updated_at":"2016-02-26T09:46:46Z","html_url":"https://github.com/alphagov/publishing-api/pull/213#discussion_r54222678","pull_request_url":"https://api.github.com/repos/alphagov/publishing-api/pulls/213","_links":{"self":{"href":"https://api.github.com/repos/alphagov/publishing-api/pulls/comments/54222678"},"html":{"href":"https://github.com/alphagov/publishing-api/pull/213#discussion_r54222678"},"pull_request":{"href":"https://api.github.com/repos/alphagov/publishing-api/pulls/213"}}},"pull_request":{"url":"https://api.github.com/repos/alphagov/publishing-api/pulls/213","id":60768514,"html_url":"https://github.com/alphagov/publishing-api/pull/213","diff_url":"https://github.com/alphagov/publishing-api/pull/213.diff","patch_url":"https://github.com/alphagov/publishing-api/pull/213.patch","issue_url":"https://api.github.com/repos/alphagov/publishing-api/issues/213","number":213,"state":"open","locked":false,"title":"Add ContentStorePayloadVersion","user":{"login":"gpeng","id":5216,"avatar_url":"https://avatars.githubusercontent.com/u/5216?v=3","gravatar_id":"","url":"https://api.github.com/users/gpeng","html_url":"https://github.com/gpeng","followers_url":"https://api.github.com/users/gpeng/followers","following_url":"https://api.github.com/users/gpeng/following{/other_user}","gists_url":"https://api.github.com/users/gpeng/gists{/gist_id}","starred_url":"https://api.github.com/users/gpeng/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gpeng/subscriptions","organizations_url":"https://api.github.com/users/gpeng/orgs","repos_url":"https://api.github.com/users/gpeng/repos","events_url":"https://api.github.com/users/gpeng/events{/privacy}","received_events_url":"https://api.github.com/users/gpeng/received_events","type":"User","site_admin":false},"body":"This PR replaces `transmitted_at` with an incrementing integer `payload_version`. Since we started 'presenting' the content items at the time the Sidekiq worker actually runs we should now be able to safely ignore payloads that have a lower or equal `payload_version`. Using an integer, incremented atomically at the DB should protect us from race conditions and negate the time variance we have between machines that was causing issues with the time based `transmitted_at`.\r\n\r\n[This PR](https://github.com/alphagov/content-store/pull/193) on Content Store added support at the 'other end'\r\n\r\n[Trello](https://trello.com/c/dBmI96gI/304-change-locking-criteria-on-content-store)","created_at":"2016-02-25T23:46:28Z","updated_at":"2016-02-26T09:46:46Z","closed_at":null,"merged_at":null,"merge_commit_sha":"aa253e1233e5a2abea42328d6d1b0a9e82e93cc8","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/alphagov/publishing-api/pulls/213/commits","review_comments_url":"https://api.github.com/repos/alphagov/publishing-api/pulls/213/comments","review_comment_url":"https://api.github.com/repos/alphagov/publishing-api/pulls/comments{/number}","comments_url":"https://api.github.com/repos/alphagov/publishing-api/issues/213/comments","statuses_url":"https://api.github.com/repos/alphagov/publishing-api/statuses/bc19b329c33d5215008c7bab768f2e5996f7011e","head":{"label":"alphagov:add_content_store_payload_version","ref":"add_content_store_payload_version","sha":"bc19b329c33d5215008c7bab768f2e5996f7011e","user":{"login":"alphagov","id":596977,"avatar_url":"https://avatars.githubusercontent.com/u/596977?v=3","gravatar_id":"","url":"https://api.github.com/users/alphagov","html_url":"https://github.com/alphagov","followers_url":"https://api.github.com/users/alphagov/followers","following_url":"https://api.github.com/users/alphagov/following{/other_user}","gists_url":"https://api.github.com/users/alphagov/gists{/gist_id}","starred_url":"https://api.github.com/users/alphagov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alphagov/subscriptions","organizations_url":"https://api.github.com/users/alphagov/orgs","repos_url":"https://api.github.com/users/alphagov/repos","events_url":"https://api.github.com/users/alphagov/events{/privacy}","received_events_url":"https://api.github.com/users/alphagov/received_events","type":"Organization","site_admin":false},"repo":{"id":27546098,"name":"publishing-api","full_name":"alphagov/publishing-api","owner":{"login":"alphagov","id":596977,"avatar_url":"https://avatars.githubusercontent.com/u/596977?v=3","gravatar_id":"","url":"https://api.github.com/users/alphagov","html_url":"https://github.com/alphagov","followers_url":"https://api.github.com/users/alphagov/followers","following_url":"https://api.github.com/users/alphagov/following{/other_user}","gists_url":"https://api.github.com/users/alphagov/gists{/gist_id}","starred_url":"https://api.github.com/users/alphagov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alphagov/subscriptions","organizations_url":"https://api.github.com/users/alphagov/orgs","repos_url":"https://api.github.com/users/alphagov/repos","events_url":"https://api.github.com/users/alphagov/events{/privacy}","received_events_url":"https://api.github.com/users/alphagov/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/alphagov/publishing-api","description":"Central store for all content on GOV.UK.","fork":false,"url":"https://api.github.com/repos/alphagov/publishing-api","forks_url":"https://api.github.com/repos/alphagov/publishing-api/forks","keys_url":"https://api.github.com/repos/alphagov/publishing-api/keys{/key_id}","collaborators_url":"https://api.github.com/repos/alphagov/publishing-api/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/alphagov/publishing-api/teams","hooks_url":"https://api.github.com/repos/alphagov/publishing-api/hooks","issue_events_url":"https://api.github.com/repos/alphagov/publishing-api/issues/events{/number}","events_url":"https://api.github.com/repos/alphagov/publishing-api/events","assignees_url":"https://api.github.com/repos/alphagov/publishing-api/assignees{/user}","branches_url":"https://api.github.com/repos/alphagov/publishing-api/branches{/branch}","tags_url":"https://api.github.com/repos/alphagov/publishing-api/tags","blobs_url":"https://api.github.com/repos/alphagov/publishing-api/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/alphagov/publishing-api/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/alphagov/publishing-api/git/refs{/sha}","trees_url":"https://api.github.com/repos/alphagov/publishing-api/git/trees{/sha}","statuses_url":"https://api.github.com/repos/alphagov/publishing-api/statuses/{sha}","languages_url":"https://api.github.com/repos/alphagov/publishing-api/languages","stargazers_url":"https://api.github.com/repos/alphagov/publishing-api/stargazers","contributors_url":"https://api.github.com/repos/alphagov/publishing-api/contributors","subscribers_url":"https://api.github.com/repos/alphagov/publishing-api/subscribers","subscription_url":"https://api.github.com/repos/alphagov/publishing-api/subscription","commits_url":"https://api.github.com/repos/alphagov/publishing-api/commits{/sha}","git_commits_url":"https://api.github.com/repos/alphagov/publishing-api/git/commits{/sha}","comments_url":"https://api.github.com/repos/alphagov/publishing-api/comments{/number}","issue_comment_url":"https://api.github.com/repos/alphagov/publishing-api/issues/comments{/number}","contents_url":"https://api.github.com/repos/alphagov/publishing-api/contents/{+path}","compare_url":"https://api.github.com/repos/alphagov/publishing-api/compare/{base}...{head}","merges_url":"https://api.github.com/repos/alphagov/publishing-api/merges","archive_url":"https://api.github.com/repos/alphagov/publishing-api/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/alphagov/publishing-api/downloads","issues_url":"https://api.github.com/repos/alphagov/publishing-api/issues{/number}","pulls_url":"https://api.github.com/repos/alphagov/publishing-api/pulls{/number}","milestones_url":"https://api.github.com/repos/alphagov/publishing-api/milestones{/number}","notifications_url":"https://api.github.com/repos/alphagov/publishing-api/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/alphagov/publishing-api/labels{/name}","releases_url":"https://api.github.com/repos/alphagov/publishing-api/releases{/id}","deployments_url":"https://api.github.com/repos/alphagov/publishing-api/deployments","created_at":"2014-12-04T15:15:43Z","updated_at":"2016-01-11T09:19:02Z","pushed_at":"2016-02-25T23:46:28Z","git_url":"git://github.com/alphagov/publishing-api.git","ssh_url":"git@github.com:alphagov/publishing-api.git","clone_url":"https://github.com/alphagov/publishing-api.git","svn_url":"https://github.com/alphagov/publishing-api","homepage":"","size":1458,"stargazers_count":3,"watchers_count":3,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3,"mirror_url":null,"open_issues_count":6,"forks":3,"open_issues":6,"watchers":3,"default_branch":"master"}},"base":{"label":"alphagov:master","ref":"master","sha":"27ae02862e4705953a053c74bd94ce759a41544d","user":{"login":"alphagov","id":596977,"avatar_url":"https://avatars.githubusercontent.com/u/596977?v=3","gravatar_id":"","url":"https://api.github.com/users/alphagov","html_url":"https://github.com/alphagov","followers_url":"https://api.github.com/users/alphagov/followers","following_url":"https://api.github.com/users/alphagov/following{/other_user}","gists_url":"https://api.github.com/users/alphagov/gists{/gist_id}","starred_url":"https://api.github.com/users/alphagov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alphagov/subscriptions","organizations_url":"https://api.github.com/users/alphagov/orgs","repos_url":"https://api.github.com/users/alphagov/repos","events_url":"https://api.github.com/users/alphagov/events{/privacy}","received_events_url":"https://api.github.com/users/alphagov/received_events","type":"Organization","site_admin":false},"repo":{"id":27546098,"name":"publishing-api","full_name":"alphagov/publishing-api","owner":{"login":"alphagov","id":596977,"avatar_url":"https://avatars.githubusercontent.com/u/596977?v=3","gravatar_id":"","url":"https://api.github.com/users/alphagov","html_url":"https://github.com/alphagov","followers_url":"https://api.github.com/users/alphagov/followers","following_url":"https://api.github.com/users/alphagov/following{/other_user}","gists_url":"https://api.github.com/users/alphagov/gists{/gist_id}","starred_url":"https://api.github.com/users/alphagov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alphagov/subscriptions","organizations_url":"https://api.github.com/users/alphagov/orgs","repos_url":"https://api.github.com/users/alphagov/repos","events_url":"https://api.github.com/users/alphagov/events{/privacy}","received_events_url":"https://api.github.com/users/alphagov/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/alphagov/publishing-api","description":"Central store for all content on GOV.UK.","fork":false,"url":"https://api.github.com/repos/alphagov/publishing-api","forks_url":"https://api.github.com/repos/alphagov/publishing-api/forks","keys_url":"https://api.github.com/repos/alphagov/publishing-api/keys{/key_id}","collaborators_url":"https://api.github.com/repos/alphagov/publishing-api/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/alphagov/publishing-api/teams","hooks_url":"https://api.github.com/repos/alphagov/publishing-api/hooks","issue_events_url":"https://api.github.com/repos/alphagov/publishing-api/issues/events{/number}","events_url":"https://api.github.com/repos/alphagov/publishing-api/events","assignees_url":"https://api.github.com/repos/alphagov/publishing-api/assignees{/user}","branches_url":"https://api.github.com/repos/alphagov/publishing-api/branches{/branch}","tags_url":"https://api.github.com/repos/alphagov/publishing-api/tags","blobs_url":"https://api.github.com/repos/alphagov/publishing-api/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/alphagov/publishing-api/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/alphagov/publishing-api/git/refs{/sha}","trees_url":"https://api.github.com/repos/alphagov/publishing-api/git/trees{/sha}","statuses_url":"https://api.github.com/repos/alphagov/publishing-api/statuses/{sha}","languages_url":"https://api.github.com/repos/alphagov/publishing-api/languages","stargazers_url":"https://api.github.com/repos/alphagov/publishing-api/stargazers","contributors_url":"https://api.github.com/repos/alphagov/publishing-api/contributors","subscribers_url":"https://api.github.com/repos/alphagov/publishing-api/subscribers","subscription_url":"https://api.github.com/repos/alphagov/publishing-api/subscription","commits_url":"https://api.github.com/repos/alphagov/publishing-api/commits{/sha}","git_commits_url":"https://api.github.com/repos/alphagov/publishing-api/git/commits{/sha}","comments_url":"https://api.github.com/repos/alphagov/publishing-api/comments{/number}","issue_comment_url":"https://api.github.com/repos/alphagov/publishing-api/issues/comments{/number}","contents_url":"https://api.github.com/repos/alphagov/publishing-api/contents/{+path}","compare_url":"https://api.github.com/repos/alphagov/publishing-api/compare/{base}...{head}","merges_url":"https://api.github.com/repos/alphagov/publishing-api/merges","archive_url":"https://api.github.com/repos/alphagov/publishing-api/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/alphagov/publishing-api/downloads","issues_url":"https://api.github.com/repos/alphagov/publishing-api/issues{/number}","pulls_url":"https://api.github.com/repos/alphagov/publishing-api/pulls{/number}","milestones_url":"https://api.github.com/repos/alphagov/publishing-api/milestones{/number}","notifications_url":"https://api.github.com/repos/alphagov/publishing-api/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/alphagov/publishing-api/labels{/name}","releases_url":"https://api.github.com/repos/alphagov/publishing-api/releases{/id}","deployments_url":"https://api.github.com/repos/alphagov/publishing-api/deployments","created_at":"2014-12-04T15:15:43Z","updated_at":"2016-01-11T09:19:02Z","pushed_at":"2016-02-25T23:46:28Z","git_url":"git://github.com/alphagov/publishing-api.git","ssh_url":"git@github.com:alphagov/publishing-api.git","clone_url":"https://github.com/alphagov/publishing-api.git","svn_url":"https://github.com/alphagov/publishing-api","homepage":"","size":1458,"stargazers_count":3,"watchers_count":3,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3,"mirror_url":null,"open_issues_count":6,"forks":3,"open_issues":6,"watchers":3,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/alphagov/publishing-api/pulls/213"},"html":{"href":"https://github.com/alphagov/publishing-api/pull/213"},"issue":{"href":"https://api.github.com/repos/alphagov/publishing-api/issues/213"},"comments":{"href":"https://api.github.com/repos/alphagov/publishing-api/issues/213/comments"},"review_comments":{"href":"https://api.github.com/repos/alphagov/publishing-api/pulls/213/comments"},"review_comment":{"href":"https://api.github.com/repos/alphagov/publishing-api/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/alphagov/publishing-api/pulls/213/commits"},"statuses":{"href":"https://api.github.com/repos/alphagov/publishing-api/statuses/bc19b329c33d5215008c7bab768f2e5996f7011e"}}}}