{"action":"created","comment":{"url":"https://api.github.com/repos/ManageIQ/manageiq/pulls/comments/40819831","id":40819831,"diff_hunk":"@@ -77,50 +75,59 @@ def self.seed\n   end\n \n   def self.seed_features\n-    idents_from_hash = []\n-    self.seed_from_hash(YAML.load_file(FIXTURE_YAML), idents_from_hash)\n+    seen = Hash.new([])\n+    features = all.to_a\n+    self.seed_from_hash(YAML.load_file(FIXTURE_YAML), seen, nil, features)\n \n-    root_feature = MiqProductFeature.where(:identifier => 'everything').first\n-    Dir.glob(File.join(FIXTURE_PATH, \"*.yml\")).each do |fixture|\n-      self.seed_from_hash(YAML.load_file(fixture), idents_from_hash, root_feature)\n-    end\n-\n-    idents_from_db = self.all.collect(&:identifier)\n-    deletes = idents_from_db - (idents_from_db & idents_from_hash)\n-    unless deletes.empty?\n-      _log.info(\"Deleting product features: #{deletes.inspect}\")\n-      self.destroy_all(:identifier => deletes)\n-    end\n+    deletes = where.not(:identifier => seen.values.flatten).destroy_all\n+    _log.info(\"Deleting product features: #{deletes.collect(&:identifier).inspect}\") unless deletes.empty?\n+    seen\n   end\n \n-  def self.seed_from_hash(hash, seen = [], parent=nil)\n+  def self.seed_from_hash(hash, seen = {}, parent = nil, features = nil)\n     children = hash.delete(:children) || []\n     hash.delete(:parent_identifier)\n \n     hash[:parent] = parent\n-    feature = self.find_by_identifier(hash[:identifier])\n+\n+    db_feature =\n+      if features\n+        features.detect { |f| f.identifier == hash[:identifier] }\n+      else\n+        where(:identifier => hash[:identifier]).first","path":"app/models/miq_product_feature.rb","position":49,"original_position":49,"commit_id":"4796e4c673ebf8fc47dda3587edcf9825118b006","original_commit_id":"4796e4c673ebf8fc47dda3587edcf9825118b006","user":{"login":"jrafanie","id":19339,"avatar_url":"https://avatars.githubusercontent.com/u/19339?v=3","gravatar_id":"","url":"https://api.github.com/users/jrafanie","html_url":"https://github.com/jrafanie","followers_url":"https://api.github.com/users/jrafanie/followers","following_url":"https://api.github.com/users/jrafanie/following{/other_user}","gists_url":"https://api.github.com/users/jrafanie/gists{/gist_id}","starred_url":"https://api.github.com/users/jrafanie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jrafanie/subscriptions","organizations_url":"https://api.github.com/users/jrafanie/orgs","repos_url":"https://api.github.com/users/jrafanie/repos","events_url":"https://api.github.com/users/jrafanie/events{/privacy}","received_events_url":"https://api.github.com/users/jrafanie/received_events","type":"User","site_admin":false},"body":"Yes, I pass it in to eliminate this N+1. The only place we don't is for seed specific features in the tests.  Normal seeding will pass in all of the features up front instead of querying them here.","created_at":"2015-09-30T16:56:36Z","updated_at":"2015-09-30T16:56:36Z","html_url":"https://github.com/ManageIQ/manageiq/pull/4581#discussion_r40819831","pull_request_url":"https://api.github.com/repos/ManageIQ/manageiq/pulls/4581","_links":{"self":{"href":"https://api.github.com/repos/ManageIQ/manageiq/pulls/comments/40819831"},"html":{"href":"https://github.com/ManageIQ/manageiq/pull/4581#discussion_r40819831"},"pull_request":{"href":"https://api.github.com/repos/ManageIQ/manageiq/pulls/4581"}}},"pull_request":{"url":"https://api.github.com/repos/ManageIQ/manageiq/pulls/4581","id":46344444,"html_url":"https://github.com/ManageIQ/manageiq/pull/4581","diff_url":"https://github.com/ManageIQ/manageiq/pull/4581.diff","patch_url":"https://github.com/ManageIQ/manageiq/pull/4581.patch","issue_url":"https://api.github.com/repos/ManageIQ/manageiq/issues/4581","number":4581,"state":"open","locked":false,"title":"Fix Product feature seed through more complete tests","user":{"login":"jrafanie","id":19339,"avatar_url":"https://avatars.githubusercontent.com/u/19339?v=3","gravatar_id":"","url":"https://api.github.com/users/jrafanie","html_url":"https://github.com/jrafanie","followers_url":"https://api.github.com/users/jrafanie/followers","following_url":"https://api.github.com/users/jrafanie/following{/other_user}","gists_url":"https://api.github.com/users/jrafanie/gists{/gist_id}","starred_url":"https://api.github.com/users/jrafanie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jrafanie/subscriptions","organizations_url":"https://api.github.com/users/jrafanie/orgs","repos_url":"https://api.github.com/users/jrafanie/repos","events_url":"https://api.github.com/users/jrafanie/events{/privacy}","received_events_url":"https://api.github.com/users/jrafanie/received_events","type":"User","site_admin":false},"body":"We have several duplicated identifiers in the `db/fixtures/miq_product_features.yml` when they must be unique.  The seed method will create on the first instance and update on each subsequent instance and the last one in the file always wins.  Since only the last one survives, I chose to delete these \"all but last duplicates\" cc @h-kataria @dclarizio \r\n\r\nTo get this list, I checked manually, but then decided to write a test so we don't accidentally add duplicates again.\r\n\r\nOnce these duplicates were eliminated, I then enhanced the tests to validate the first seed does only creates, a subsequent seed does not make any changes and eliminated some slowness (11 seconds -> 6 locally).\r\n\r\nFinally, I also removed the unused \"feature\" to seed product features from the non-existing `db/fixtures/miq_product_features` directory.  cc @Fryguy @gtanzillo @dclarizio Please let me know if this was wrong, I can't see this being used.","created_at":"2015-09-29T23:15:30Z","updated_at":"2015-09-30T16:56:36Z","closed_at":null,"merged_at":null,"merge_commit_sha":"6d060cb5020480675aea8135f240d384e955df6a","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/ManageIQ/manageiq/pulls/4581/commits","review_comments_url":"https://api.github.com/repos/ManageIQ/manageiq/pulls/4581/comments","review_comment_url":"https://api.github.com/repos/ManageIQ/manageiq/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ManageIQ/manageiq/issues/4581/comments","statuses_url":"https://api.github.com/repos/ManageIQ/manageiq/statuses/4796e4c673ebf8fc47dda3587edcf9825118b006","head":{"label":"jrafanie:product_feature_seed","ref":"product_feature_seed","sha":"4796e4c673ebf8fc47dda3587edcf9825118b006","user":{"login":"jrafanie","id":19339,"avatar_url":"https://avatars.githubusercontent.com/u/19339?v=3","gravatar_id":"","url":"https://api.github.com/users/jrafanie","html_url":"https://github.com/jrafanie","followers_url":"https://api.github.com/users/jrafanie/followers","following_url":"https://api.github.com/users/jrafanie/following{/other_user}","gists_url":"https://api.github.com/users/jrafanie/gists{/gist_id}","starred_url":"https://api.github.com/users/jrafanie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jrafanie/subscriptions","organizations_url":"https://api.github.com/users/jrafanie/orgs","repos_url":"https://api.github.com/users/jrafanie/repos","events_url":"https://api.github.com/users/jrafanie/events{/privacy}","received_events_url":"https://api.github.com/users/jrafanie/received_events","type":"User","site_admin":false},"repo":{"id":20803842,"name":"manageiq","full_name":"jrafanie/manageiq","owner":{"login":"jrafanie","id":19339,"avatar_url":"https://avatars.githubusercontent.com/u/19339?v=3","gravatar_id":"","url":"https://api.github.com/users/jrafanie","html_url":"https://github.com/jrafanie","followers_url":"https://api.github.com/users/jrafanie/followers","following_url":"https://api.github.com/users/jrafanie/following{/other_user}","gists_url":"https://api.github.com/users/jrafanie/gists{/gist_id}","starred_url":"https://api.github.com/users/jrafanie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jrafanie/subscriptions","organizations_url":"https://api.github.com/users/jrafanie/orgs","repos_url":"https://api.github.com/users/jrafanie/repos","events_url":"https://api.github.com/users/jrafanie/events{/privacy}","received_events_url":"https://api.github.com/users/jrafanie/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jrafanie/manageiq","description":"ManageIQ Cloud Management Platform","fork":true,"url":"https://api.github.com/repos/jrafanie/manageiq","forks_url":"https://api.github.com/repos/jrafanie/manageiq/forks","keys_url":"https://api.github.com/repos/jrafanie/manageiq/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jrafanie/manageiq/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jrafanie/manageiq/teams","hooks_url":"https://api.github.com/repos/jrafanie/manageiq/hooks","issue_events_url":"https://api.github.com/repos/jrafanie/manageiq/issues/events{/number}","events_url":"https://api.github.com/repos/jrafanie/manageiq/events","assignees_url":"https://api.github.com/repos/jrafanie/manageiq/assignees{/user}","branches_url":"https://api.github.com/repos/jrafanie/manageiq/branches{/branch}","tags_url":"https://api.github.com/repos/jrafanie/manageiq/tags","blobs_url":"https://api.github.com/repos/jrafanie/manageiq/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jrafanie/manageiq/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jrafanie/manageiq/git/refs{/sha}","trees_url":"https://api.github.com/repos/jrafanie/manageiq/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jrafanie/manageiq/statuses/{sha}","languages_url":"https://api.github.com/repos/jrafanie/manageiq/languages","stargazers_url":"https://api.github.com/repos/jrafanie/manageiq/stargazers","contributors_url":"https://api.github.com/repos/jrafanie/manageiq/contributors","subscribers_url":"https://api.github.com/repos/jrafanie/manageiq/subscribers","subscription_url":"https://api.github.com/repos/jrafanie/manageiq/subscription","commits_url":"https://api.github.com/repos/jrafanie/manageiq/commits{/sha}","git_commits_url":"https://api.github.com/repos/jrafanie/manageiq/git/commits{/sha}","comments_url":"https://api.github.com/repos/jrafanie/manageiq/comments{/number}","issue_comment_url":"https://api.github.com/repos/jrafanie/manageiq/issues/comments{/number}","contents_url":"https://api.github.com/repos/jrafanie/manageiq/contents/{+path}","compare_url":"https://api.github.com/repos/jrafanie/manageiq/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jrafanie/manageiq/merges","archive_url":"https://api.github.com/repos/jrafanie/manageiq/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jrafanie/manageiq/downloads","issues_url":"https://api.github.com/repos/jrafanie/manageiq/issues{/number}","pulls_url":"https://api.github.com/repos/jrafanie/manageiq/pulls{/number}","milestones_url":"https://api.github.com/repos/jrafanie/manageiq/milestones{/number}","notifications_url":"https://api.github.com/repos/jrafanie/manageiq/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jrafanie/manageiq/labels{/name}","releases_url":"https://api.github.com/repos/jrafanie/manageiq/releases{/id}","created_at":"2014-06-13T12:47:01Z","updated_at":"2015-04-02T16:14:36Z","pushed_at":"2015-09-30T16:36:13Z","git_url":"git://github.com/jrafanie/manageiq.git","ssh_url":"git@github.com:jrafanie/manageiq.git","clone_url":"https://github.com/jrafanie/manageiq.git","svn_url":"https://github.com/jrafanie/manageiq","homepage":null,"size":86510,"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":"ManageIQ:master","ref":"master","sha":"24351dff45bf65a26674f10efea2cc21d4e4b13a","user":{"login":"ManageIQ","id":1125575,"avatar_url":"https://avatars.githubusercontent.com/u/1125575?v=3","gravatar_id":"","url":"https://api.github.com/users/ManageIQ","html_url":"https://github.com/ManageIQ","followers_url":"https://api.github.com/users/ManageIQ/followers","following_url":"https://api.github.com/users/ManageIQ/following{/other_user}","gists_url":"https://api.github.com/users/ManageIQ/gists{/gist_id}","starred_url":"https://api.github.com/users/ManageIQ/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ManageIQ/subscriptions","organizations_url":"https://api.github.com/users/ManageIQ/orgs","repos_url":"https://api.github.com/users/ManageIQ/repos","events_url":"https://api.github.com/users/ManageIQ/events{/privacy}","received_events_url":"https://api.github.com/users/ManageIQ/received_events","type":"Organization","site_admin":false},"repo":{"id":20789757,"name":"manageiq","full_name":"ManageIQ/manageiq","owner":{"login":"ManageIQ","id":1125575,"avatar_url":"https://avatars.githubusercontent.com/u/1125575?v=3","gravatar_id":"","url":"https://api.github.com/users/ManageIQ","html_url":"https://github.com/ManageIQ","followers_url":"https://api.github.com/users/ManageIQ/followers","following_url":"https://api.github.com/users/ManageIQ/following{/other_user}","gists_url":"https://api.github.com/users/ManageIQ/gists{/gist_id}","starred_url":"https://api.github.com/users/ManageIQ/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ManageIQ/subscriptions","organizations_url":"https://api.github.com/users/ManageIQ/orgs","repos_url":"https://api.github.com/users/ManageIQ/repos","events_url":"https://api.github.com/users/ManageIQ/events{/privacy}","received_events_url":"https://api.github.com/users/ManageIQ/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ManageIQ/manageiq","description":"ManageIQ Cloud Management Platform","fork":false,"url":"https://api.github.com/repos/ManageIQ/manageiq","forks_url":"https://api.github.com/repos/ManageIQ/manageiq/forks","keys_url":"https://api.github.com/repos/ManageIQ/manageiq/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ManageIQ/manageiq/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ManageIQ/manageiq/teams","hooks_url":"https://api.github.com/repos/ManageIQ/manageiq/hooks","issue_events_url":"https://api.github.com/repos/ManageIQ/manageiq/issues/events{/number}","events_url":"https://api.github.com/repos/ManageIQ/manageiq/events","assignees_url":"https://api.github.com/repos/ManageIQ/manageiq/assignees{/user}","branches_url":"https://api.github.com/repos/ManageIQ/manageiq/branches{/branch}","tags_url":"https://api.github.com/repos/ManageIQ/manageiq/tags","blobs_url":"https://api.github.com/repos/ManageIQ/manageiq/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ManageIQ/manageiq/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ManageIQ/manageiq/git/refs{/sha}","trees_url":"https://api.github.com/repos/ManageIQ/manageiq/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ManageIQ/manageiq/statuses/{sha}","languages_url":"https://api.github.com/repos/ManageIQ/manageiq/languages","stargazers_url":"https://api.github.com/repos/ManageIQ/manageiq/stargazers","contributors_url":"https://api.github.com/repos/ManageIQ/manageiq/contributors","subscribers_url":"https://api.github.com/repos/ManageIQ/manageiq/subscribers","subscription_url":"https://api.github.com/repos/ManageIQ/manageiq/subscription","commits_url":"https://api.github.com/repos/ManageIQ/manageiq/commits{/sha}","git_commits_url":"https://api.github.com/repos/ManageIQ/manageiq/git/commits{/sha}","comments_url":"https://api.github.com/repos/ManageIQ/manageiq/comments{/number}","issue_comment_url":"https://api.github.com/repos/ManageIQ/manageiq/issues/comments{/number}","contents_url":"https://api.github.com/repos/ManageIQ/manageiq/contents/{+path}","compare_url":"https://api.github.com/repos/ManageIQ/manageiq/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ManageIQ/manageiq/merges","archive_url":"https://api.github.com/repos/ManageIQ/manageiq/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ManageIQ/manageiq/downloads","issues_url":"https://api.github.com/repos/ManageIQ/manageiq/issues{/number}","pulls_url":"https://api.github.com/repos/ManageIQ/manageiq/pulls{/number}","milestones_url":"https://api.github.com/repos/ManageIQ/manageiq/milestones{/number}","notifications_url":"https://api.github.com/repos/ManageIQ/manageiq/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ManageIQ/manageiq/labels{/name}","releases_url":"https://api.github.com/repos/ManageIQ/manageiq/releases{/id}","created_at":"2014-06-13T02:31:26Z","updated_at":"2015-09-30T14:31:51Z","pushed_at":"2015-09-30T16:49:28Z","git_url":"git://github.com/ManageIQ/manageiq.git","ssh_url":"git@github.com:ManageIQ/manageiq.git","clone_url":"https://github.com/ManageIQ/manageiq.git","svn_url":"https://github.com/ManageIQ/manageiq","homepage":"manageiq.org","size":168010,"stargazers_count":154,"watchers_count":154,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":160,"mirror_url":null,"open_issues_count":431,"forks":160,"open_issues":431,"watchers":154,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ManageIQ/manageiq/pulls/4581"},"html":{"href":"https://github.com/ManageIQ/manageiq/pull/4581"},"issue":{"href":"https://api.github.com/repos/ManageIQ/manageiq/issues/4581"},"comments":{"href":"https://api.github.com/repos/ManageIQ/manageiq/issues/4581/comments"},"review_comments":{"href":"https://api.github.com/repos/ManageIQ/manageiq/pulls/4581/comments"},"review_comment":{"href":"https://api.github.com/repos/ManageIQ/manageiq/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ManageIQ/manageiq/pulls/4581/commits"},"statuses":{"href":"https://api.github.com/repos/ManageIQ/manageiq/statuses/4796e4c673ebf8fc47dda3587edcf9825118b006"}}}}