{"action":"created","comment":{"url":"https://api.github.com/repos/alphagov/publishing-api/pulls/comments/45190394","id":45190394,"diff_hunk":"@@ -1,42 +1,26 @@\n class LinkSet < ActiveRecord::Base\n-  include Replaceable\n-  include DefaultAttributes\n-  include SymbolizeJSON\n-\n-  validate :links_are_valid\n+  has_many :links\n \n-  def links=(links_hash)\n-    super(links_hash || {})\n-  end\n+  include Replaceable\n \n-private\n-  def self.query_keys\n-    [:content_id]\n-  end\n+  def hashed_links\n+    links = Link.where(link_set: self)\n \n-  def links_are_valid\n-    # Test that the `links` attribute, if set, is a hash from strings to lists\n-    # of UUIDs\n-    return if links.empty?\n+    links_hash = Hash.new\n \n-    bad_keys = links.keys.reject { |key| link_key_is_valid?(key) }\n-    if bad_keys.any?\n-      errors[:links] = \"Invalid link types: #{bad_keys.to_sentence}\"\n+    links.each do |l|\n+      if links_hash.has_key?(l.link_type)\n+        links_hash[l.link_type] << l.target_content_id\n+      else\n+        links_hash[l.link_type] = [l.target_content_id]\n+      end\n     end\n \n-    bad_values = links.values.reject { |value|\n-      value.is_a?(Array) && value.all? { |content_id|\n-        UuidValidator.valid?(content_id)\n-      }\n-    }\n-    if bad_values.any?\n-      errors[:links] = \"must map to lists of UUIDs\"\n-    end\n+    links_hash.symbolize_keys","path":"app/models/link_set.rb","position":46,"original_position":46,"commit_id":"03ae76bd3969d56bbcb52c42723ee6ac9f4729f2","original_commit_id":"3122e9847fb402ee673f57155023104752e80599","user":{"login":"jackscotti","id":5038475,"avatar_url":"https://avatars.githubusercontent.com/u/5038475?v=3","gravatar_id":"","url":"https://api.github.com/users/jackscotti","html_url":"https://github.com/jackscotti","followers_url":"https://api.github.com/users/jackscotti/followers","following_url":"https://api.github.com/users/jackscotti/following{/other_user}","gists_url":"https://api.github.com/users/jackscotti/gists{/gist_id}","starred_url":"https://api.github.com/users/jackscotti/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jackscotti/subscriptions","organizations_url":"https://api.github.com/users/jackscotti/orgs","repos_url":"https://api.github.com/users/jackscotti/repos","events_url":"https://api.github.com/users/jackscotti/events{/privacy}","received_events_url":"https://api.github.com/users/jackscotti/received_events","type":"User","site_admin":false},"body":"What would this do?","created_at":"2015-11-18T11:55:08Z","updated_at":"2015-11-18T11:55:08Z","html_url":"https://github.com/alphagov/publishing-api/pull/137#discussion_r45190394","pull_request_url":"https://api.github.com/repos/alphagov/publishing-api/pulls/137","_links":{"self":{"href":"https://api.github.com/repos/alphagov/publishing-api/pulls/comments/45190394"},"html":{"href":"https://github.com/alphagov/publishing-api/pull/137#discussion_r45190394"},"pull_request":{"href":"https://api.github.com/repos/alphagov/publishing-api/pulls/137"}}},"pull_request":{"url":"https://api.github.com/repos/alphagov/publishing-api/pulls/137","id":50935942,"html_url":"https://github.com/alphagov/publishing-api/pull/137","diff_url":"https://github.com/alphagov/publishing-api/pull/137.diff","patch_url":"https://github.com/alphagov/publishing-api/pull/137.patch","issue_url":"https://api.github.com/repos/alphagov/publishing-api/issues/137","number":137,"state":"open","locked":false,"title":"[Blocked by RFC36]Extract LinkSet's links column into its own table","user":{"login":"jackscotti","id":5038475,"avatar_url":"https://avatars.githubusercontent.com/u/5038475?v=3","gravatar_id":"","url":"https://api.github.com/users/jackscotti","html_url":"https://github.com/jackscotti","followers_url":"https://api.github.com/users/jackscotti/followers","following_url":"https://api.github.com/users/jackscotti/following{/other_user}","gists_url":"https://api.github.com/users/jackscotti/gists{/gist_id}","starred_url":"https://api.github.com/users/jackscotti/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jackscotti/subscriptions","organizations_url":"https://api.github.com/users/jackscotti/orgs","repos_url":"https://api.github.com/users/jackscotti/repos","events_url":"https://api.github.com/users/jackscotti/events{/privacy}","received_events_url":"https://api.github.com/users/jackscotti/received_events","type":"User","site_admin":false},"body":"Why:\r\n\r\n- We want to introduce a [`get-linked-endpoint`](https://gov-uk.atlassian.net/wiki/display/FS/RFC+31%3A+Requirements+for+tagging+architecture). And in order to do that we need to be able to query the links easily. The current version of Postgres (9.4) does not allow us to do that, we therefore need to extract the `links` column into its own table.\r\n- This work will also ease any other future query on the links data\r\n\r\nDONE:\r\n\r\n- Introduced a `Links` table\r\n- Updated the logic of the app to use that able instead of the `links` column in the `LinkSets` table\r\n- Populated the `Links` table with a migraiton\r\n- Dropped the `links` column from `LinkSet` table with a migration\r\n\r\nTODO:\r\n\r\n- [x] Validate links somewhere (possibly within the `Link` model)\r\n- [x] Address comments\r\n- [x] Rename this branch\r\n- [x] Make `LinkSet` behave like a `Replaceable`\r\n\r\nBlockers:\r\n- This work will make the app stop preserving the order in which the links are stored in it. \r\nLuckily enough there is an RFC just about that:\r\n[RFC 36](https://gov-uk.atlassian.net/wiki/display/FS/RFC+36%3A+Stop+preserving+order+for+links).\r\n\r\nYou should only merge this PR if the RFC is accepted. We shoul also check whether some applications will not be able to handle the this new behaviour .\r\n\r\nTrello Ticket:\r\nhttps://trello.com/c/zppxFP6p/345-implement-the-publisher-get-linked-endpoint","created_at":"2015-11-17T11:38:43Z","updated_at":"2015-11-18T11:55:08Z","closed_at":null,"merged_at":null,"merge_commit_sha":"47e173c541be5a7b3e41ef4ca1c6c288886dc1b4","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/alphagov/publishing-api/pulls/137/commits","review_comments_url":"https://api.github.com/repos/alphagov/publishing-api/pulls/137/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/137/comments","statuses_url":"https://api.github.com/repos/alphagov/publishing-api/statuses/03ae76bd3969d56bbcb52c42723ee6ac9f4729f2","head":{"label":"alphagov:extract-links-column-into-a-table","ref":"extract-links-column-into-a-table","sha":"03ae76bd3969d56bbcb52c42723ee6ac9f4729f2","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":"An application to forward requests to multiple content-stores based on their state.","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}","created_at":"2014-12-04T15:15:43Z","updated_at":"2015-08-03T08:55:08Z","pushed_at":"2015-11-18T11:50:08Z","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":919,"stargazers_count":1,"watchers_count":1,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":5,"forks":2,"open_issues":5,"watchers":1,"default_branch":"master"}},"base":{"label":"alphagov:master","ref":"master","sha":"e1e9d95a4af7fd259b05497feb160bc8451e89e7","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":"An application to forward requests to multiple content-stores based on their state.","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}","created_at":"2014-12-04T15:15:43Z","updated_at":"2015-08-03T08:55:08Z","pushed_at":"2015-11-18T11:50:08Z","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":919,"stargazers_count":1,"watchers_count":1,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":5,"forks":2,"open_issues":5,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/alphagov/publishing-api/pulls/137"},"html":{"href":"https://github.com/alphagov/publishing-api/pull/137"},"issue":{"href":"https://api.github.com/repos/alphagov/publishing-api/issues/137"},"comments":{"href":"https://api.github.com/repos/alphagov/publishing-api/issues/137/comments"},"review_comments":{"href":"https://api.github.com/repos/alphagov/publishing-api/pulls/137/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/137/commits"},"statuses":{"href":"https://api.github.com/repos/alphagov/publishing-api/statuses/03ae76bd3969d56bbcb52c42723ee6ac9f4729f2"}}}}