{"action":"created","comment":{"url":"https://api.github.com/repos/wagn/wikirate/pulls/comments/79059613","id":79059613,"diff_hunk":"@@ -1,153 +1,68 @@\n # cache all values in a json hash of the form\n-# company => [{ year => ..., value => ...}, ... ]\n+# company_id => [{ year => ..., value => ...}, ... ]\n \n-include Card::CachedCount\n+include_set Abstract::SolidCache, cached_format: :json\n \n # recount # of values for a metric when ...\n \n # ... a +value is changed\n ensure_set { TypePlusRight::MetricValue::Value }\n ensure_set { Type::MetricValue }\n \n-recount_trigger TypePlusRight::MetricValue::Value do |changed_card|\n-  metric_cache = [changed_card.metric_card.fetch(trait: :all_values)]\n-  # changed names with nil mean create or delete\n-  if changed_card.name_changed? && !changed_card.name_change.include?(nil)\n-    old_metric_name = changed_card.name_change[0].to_name.parts[0..-4].join \"+\"\n-    if !old_metric_name.empty? && old_metric_name != changed_card.metric\n-      metric_cache.push Card.fetch(old_metric_name).fetch(trait: :all_values)\n-    end\n-  end\n-  metric_cache\n-end\n-\n-# company rename and delete changes should also trigger the update?\n \n-# ... a Metric Value (type) is renamed, and deleted\n-recount_trigger Type::MetricValue do |changed_card|\n-  metric_cache = [changed_card.metric_card.fetch(trait: :all_values)]\n-  # it should also update the cache for the old name\n+def self.value_caches_affected_by_metric_child_update changed_card\n+  needs_update = changed_card.metric_card &&\n+    [changed_card.metric_card.all_values_card]\n+  needs_update ||= []\n   if changed_card.name_changed?\n-    old_metric_name = changed_card.name_change[0].to_name.parts[0..-3].join \"+\"\n-    if !old_metric_name.empty? && old_metric_name != changed_card.metric_name\n-      metric_cache.push Card.fetch(old_metric_name).fetch(trait: :all_values)\n-    end\n-  end\n-  metric_cache\n-end\n-\n-# get all metric values\n-def calculate_count changed_card=nil\n-  if changed_card && fetch(trait: :cached_count)\n-    cached_hash = construct_cached_hash\n-    # name changed?\n-    if changed_card.name_changed? && !changed_card.name_change.include?(nil)\n-      add_or_remove_value changed_card, cached_hash\n-    else\n-      cud_value_from_hash changed_card, cached_hash\n-    end\n-    cached_hash.to_json\n-  else\n-    refresh_cache_completely\n-  end\n-end\n-\n-def cud_value_from_hash changed_card, cached_hash\n-  if changed_card.trash?\n-    # value created or deleted or update\n-    # remove it from the cache\n-    remove_value_from_hash changed_card, cached_hash\n-  else\n-    # find if it exists in cache\n-    # exist -> update\n-    # not exist -> add one\n-    add_or_update_value changed_card, cached_hash\n-  end\n-end\n-\n-def extract_name card, type, from=:new\n-  offset = card.type_id == Card::MetricValueID ? 0 : 1\n-  cardname = card_name(card, from).parts\n-  case type\n-  when :metric\n-    cardname[0..-3 - offset].join(\"+\")\n-  when :year\n-    cardname[-1 - offset]\n-  when :company\n-    cardname[-2 - offset]\n+    old_metric = changed_card.metric_card_before_name_change\n+    needs_update << old_metric.all_values_card if old_metric\n   end\n+  needs_update\n end\n \n-def card_name card, from\n-  from == :new ? card.cardname : card.name_change[0].to_name\n+cache_update_trigger TypePlusRight::MetricValue::Value,\n+                     on: :save do |changed_card|\n+  value_caches_affected_by_metric_child_update changed_card\n end\n \n-def add_or_remove_value changed_card, cached_hash\n-  new_metric = extract_name(changed_card, :metric)\n-  if new_metric == metric\n-    # remove value from the same cache\n-    remove_value_from_hash changed_card, cached_hash\n-    add_value_to_hash changed_card, cached_hash\n-  else\n-    remove_value_from_hash changed_card, cached_hash\n-  end\n+cache_update_trigger Type::MetricValue,\n+                     on: :delete do |changed_card|\n+  # don't trigger the update if the metric itself was deleted\n+  (mc = changed_card.metric_card) && !mc.trash && mc.all_values_card\n end\n \n-def get_record_from_year records, year\n-  record = records.select { |row| row[\"year\"] == year }\n-  record.empty? ? nil : record[0]\n+cache_update_trigger TypePlusRight::MetricValue::Value,\n+                     on: :delete do |changed_card|\n+  # don't update if parent dealt with it\n+  next if @supercard && @supercard.type_id == MetricValueID &&\n+            @supercard.trash\n+  # don't trigger the update if the metric itself was deleted\n+  (mc = changed_card.metric_card) && !mc.trash && mc.all_values_card\n end\n \n-def get_value_card changed_card\n-  if changed_card.type_id == Card::MetricValueID\n-    changed_card.fetch trait: :value\n-  else\n-    changed_card\n-  end\n+# ... a Metric Value (type) is renamed\n+cache_update_trigger Type::MetricValue, on: :update do |changed_card|\n+  value_caches_affected_by_metric_child_update changed_card\n end\n \n-def add_or_update_value changed_card, cached_hash\n-  company_id = get_key changed_card\n-  cached_hash[company_id] = [] unless cached_hash.key?(company_id)\n-  rows = cached_hash[company_id]\n-  row = get_record_from_year(rows, changed_card.year)\n-  value_card = get_value_card changed_card\n-  if rows.empty? || row.nil?\n-    rows.push construct_a_row(value_card)\n-  else\n-    row[:value] = value_card.value\n-  end\n+# ... a Metric Value (type) is renamed\n+cache_update_trigger Type::MetricValue, on: :update do |changed_card|\n+  value_caches_affected_by_metric_child_update changed_card\n end\n \n-def construct_a_row value_card\n-  { year: value_card.year, value: value_card.value,\n-    last_update_time: value_card.updated_at.to_i }\n-end\n+# ... a Metric Value (type) is renamed\n+# cache_update_trigger TypePlusRight::MetricValue::Company, on: :update do |changed_card|","path":"mod/caching/set/type_plus_right/metric/all_values.rb","position":156,"original_position":156,"commit_id":"fffc52e7262000d18d239329bbecb981442f0bdb","original_commit_id":"fffc52e7262000d18d239329bbecb981442f0bdb","user":{"login":"houndci-bot","id":6697940,"avatar_url":"https://avatars.githubusercontent.com/u/6697940?v=3","gravatar_id":"","url":"https://api.github.com/users/houndci-bot","html_url":"https://github.com/houndci-bot","followers_url":"https://api.github.com/users/houndci-bot/followers","following_url":"https://api.github.com/users/houndci-bot/following{/other_user}","gists_url":"https://api.github.com/users/houndci-bot/gists{/gist_id}","starred_url":"https://api.github.com/users/houndci-bot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/houndci-bot/subscriptions","organizations_url":"https://api.github.com/users/houndci-bot/orgs","repos_url":"https://api.github.com/users/houndci-bot/repos","events_url":"https://api.github.com/users/houndci-bot/events{/privacy}","received_events_url":"https://api.github.com/users/houndci-bot/received_events","type":"User","site_admin":false},"body":"Line is too long. [89/80]","created_at":"2016-09-15T20:55:02Z","updated_at":"2016-09-15T20:55:02Z","html_url":"https://github.com/wagn/wikirate/pull/494#discussion_r79059613","pull_request_url":"https://api.github.com/repos/wagn/wikirate/pulls/494","_links":{"self":{"href":"https://api.github.com/repos/wagn/wikirate/pulls/comments/79059613"},"html":{"href":"https://github.com/wagn/wikirate/pull/494#discussion_r79059613"},"pull_request":{"href":"https://api.github.com/repos/wagn/wikirate/pulls/494"}}},"pull_request":{"url":"https://api.github.com/repos/wagn/wikirate/pulls/494","id":85085480,"html_url":"https://github.com/wagn/wikirate/pull/494","diff_url":"https://github.com/wagn/wikirate/pull/494.diff","patch_url":"https://github.com/wagn/wikirate/pull/494.patch","issue_url":"https://api.github.com/repos/wagn/wikirate/issues/494","number":494,"state":"open","locked":false,"title":"refactoring \"all values\"","user":{"login":"xithan","id":13584,"avatar_url":"https://avatars.githubusercontent.com/u/13584?v=3","gravatar_id":"","url":"https://api.github.com/users/xithan","html_url":"https://github.com/xithan","followers_url":"https://api.github.com/users/xithan/followers","following_url":"https://api.github.com/users/xithan/following{/other_user}","gists_url":"https://api.github.com/users/xithan/gists{/gist_id}","starred_url":"https://api.github.com/users/xithan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xithan/subscriptions","organizations_url":"https://api.github.com/users/xithan/orgs","repos_url":"https://api.github.com/users/xithan/repos","events_url":"https://api.github.com/users/xithan/events{/privacy}","received_events_url":"https://api.github.com/users/xithan/received_events","type":"User","site_admin":false},"body":"work in progress","created_at":"2016-09-13T16:52:49Z","updated_at":"2016-09-15T20:55:02Z","closed_at":null,"merged_at":null,"merge_commit_sha":"290db027c91cf5d050158ba272d06b6660285e30","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/wagn/wikirate/pulls/494/commits","review_comments_url":"https://api.github.com/repos/wagn/wikirate/pulls/494/comments","review_comment_url":"https://api.github.com/repos/wagn/wikirate/pulls/comments{/number}","comments_url":"https://api.github.com/repos/wagn/wikirate/issues/494/comments","statuses_url":"https://api.github.com/repos/wagn/wikirate/statuses/fffc52e7262000d18d239329bbecb981442f0bdb","head":{"label":"xithan:all_values","ref":"all_values","sha":"fffc52e7262000d18d239329bbecb981442f0bdb","user":{"login":"xithan","id":13584,"avatar_url":"https://avatars.githubusercontent.com/u/13584?v=3","gravatar_id":"","url":"https://api.github.com/users/xithan","html_url":"https://github.com/xithan","followers_url":"https://api.github.com/users/xithan/followers","following_url":"https://api.github.com/users/xithan/following{/other_user}","gists_url":"https://api.github.com/users/xithan/gists{/gist_id}","starred_url":"https://api.github.com/users/xithan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xithan/subscriptions","organizations_url":"https://api.github.com/users/xithan/orgs","repos_url":"https://api.github.com/users/xithan/repos","events_url":"https://api.github.com/users/xithan/events{/privacy}","received_events_url":"https://api.github.com/users/xithan/received_events","type":"User","site_admin":false},"repo":{"id":20190741,"name":"wikirate","full_name":"xithan/wikirate","owner":{"login":"xithan","id":13584,"avatar_url":"https://avatars.githubusercontent.com/u/13584?v=3","gravatar_id":"","url":"https://api.github.com/users/xithan","html_url":"https://github.com/xithan","followers_url":"https://api.github.com/users/xithan/followers","following_url":"https://api.github.com/users/xithan/following{/other_user}","gists_url":"https://api.github.com/users/xithan/gists{/gist_id}","starred_url":"https://api.github.com/users/xithan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xithan/subscriptions","organizations_url":"https://api.github.com/users/xithan/orgs","repos_url":"https://api.github.com/users/xithan/repos","events_url":"https://api.github.com/users/xithan/events{/privacy}","received_events_url":"https://api.github.com/users/xithan/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/xithan/wikirate","description":"","fork":true,"url":"https://api.github.com/repos/xithan/wikirate","forks_url":"https://api.github.com/repos/xithan/wikirate/forks","keys_url":"https://api.github.com/repos/xithan/wikirate/keys{/key_id}","collaborators_url":"https://api.github.com/repos/xithan/wikirate/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/xithan/wikirate/teams","hooks_url":"https://api.github.com/repos/xithan/wikirate/hooks","issue_events_url":"https://api.github.com/repos/xithan/wikirate/issues/events{/number}","events_url":"https://api.github.com/repos/xithan/wikirate/events","assignees_url":"https://api.github.com/repos/xithan/wikirate/assignees{/user}","branches_url":"https://api.github.com/repos/xithan/wikirate/branches{/branch}","tags_url":"https://api.github.com/repos/xithan/wikirate/tags","blobs_url":"https://api.github.com/repos/xithan/wikirate/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/xithan/wikirate/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/xithan/wikirate/git/refs{/sha}","trees_url":"https://api.github.com/repos/xithan/wikirate/git/trees{/sha}","statuses_url":"https://api.github.com/repos/xithan/wikirate/statuses/{sha}","languages_url":"https://api.github.com/repos/xithan/wikirate/languages","stargazers_url":"https://api.github.com/repos/xithan/wikirate/stargazers","contributors_url":"https://api.github.com/repos/xithan/wikirate/contributors","subscribers_url":"https://api.github.com/repos/xithan/wikirate/subscribers","subscription_url":"https://api.github.com/repos/xithan/wikirate/subscription","commits_url":"https://api.github.com/repos/xithan/wikirate/commits{/sha}","git_commits_url":"https://api.github.com/repos/xithan/wikirate/git/commits{/sha}","comments_url":"https://api.github.com/repos/xithan/wikirate/comments{/number}","issue_comment_url":"https://api.github.com/repos/xithan/wikirate/issues/comments{/number}","contents_url":"https://api.github.com/repos/xithan/wikirate/contents/{+path}","compare_url":"https://api.github.com/repos/xithan/wikirate/compare/{base}...{head}","merges_url":"https://api.github.com/repos/xithan/wikirate/merges","archive_url":"https://api.github.com/repos/xithan/wikirate/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/xithan/wikirate/downloads","issues_url":"https://api.github.com/repos/xithan/wikirate/issues{/number}","pulls_url":"https://api.github.com/repos/xithan/wikirate/pulls{/number}","milestones_url":"https://api.github.com/repos/xithan/wikirate/milestones{/number}","notifications_url":"https://api.github.com/repos/xithan/wikirate/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/xithan/wikirate/labels{/name}","releases_url":"https://api.github.com/repos/xithan/wikirate/releases{/id}","deployments_url":"https://api.github.com/repos/xithan/wikirate/deployments","created_at":"2014-05-26T15:35:11Z","updated_at":"2016-09-06T07:35:28Z","pushed_at":"2016-09-15T20:54:38Z","git_url":"git://github.com/xithan/wikirate.git","ssh_url":"git@github.com:xithan/wikirate.git","clone_url":"https://github.com/xithan/wikirate.git","svn_url":"https://github.com/xithan/wikirate","homepage":null,"size":99137,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"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":"wagn:master","ref":"master","sha":"275b407b14c57414f0a462f62110a524dde2ff9f","user":{"login":"wagn","id":20722,"avatar_url":"https://avatars.githubusercontent.com/u/20722?v=3","gravatar_id":"","url":"https://api.github.com/users/wagn","html_url":"https://github.com/wagn","followers_url":"https://api.github.com/users/wagn/followers","following_url":"https://api.github.com/users/wagn/following{/other_user}","gists_url":"https://api.github.com/users/wagn/gists{/gist_id}","starred_url":"https://api.github.com/users/wagn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wagn/subscriptions","organizations_url":"https://api.github.com/users/wagn/orgs","repos_url":"https://api.github.com/users/wagn/repos","events_url":"https://api.github.com/users/wagn/events{/privacy}","received_events_url":"https://api.github.com/users/wagn/received_events","type":"User","site_admin":false},"repo":{"id":15884166,"name":"wikirate","full_name":"wagn/wikirate","owner":{"login":"wagn","id":20722,"avatar_url":"https://avatars.githubusercontent.com/u/20722?v=3","gravatar_id":"","url":"https://api.github.com/users/wagn","html_url":"https://github.com/wagn","followers_url":"https://api.github.com/users/wagn/followers","following_url":"https://api.github.com/users/wagn/following{/other_user}","gists_url":"https://api.github.com/users/wagn/gists{/gist_id}","starred_url":"https://api.github.com/users/wagn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wagn/subscriptions","organizations_url":"https://api.github.com/users/wagn/orgs","repos_url":"https://api.github.com/users/wagn/repos","events_url":"https://api.github.com/users/wagn/events{/privacy}","received_events_url":"https://api.github.com/users/wagn/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/wagn/wikirate","description":"","fork":false,"url":"https://api.github.com/repos/wagn/wikirate","forks_url":"https://api.github.com/repos/wagn/wikirate/forks","keys_url":"https://api.github.com/repos/wagn/wikirate/keys{/key_id}","collaborators_url":"https://api.github.com/repos/wagn/wikirate/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/wagn/wikirate/teams","hooks_url":"https://api.github.com/repos/wagn/wikirate/hooks","issue_events_url":"https://api.github.com/repos/wagn/wikirate/issues/events{/number}","events_url":"https://api.github.com/repos/wagn/wikirate/events","assignees_url":"https://api.github.com/repos/wagn/wikirate/assignees{/user}","branches_url":"https://api.github.com/repos/wagn/wikirate/branches{/branch}","tags_url":"https://api.github.com/repos/wagn/wikirate/tags","blobs_url":"https://api.github.com/repos/wagn/wikirate/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/wagn/wikirate/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/wagn/wikirate/git/refs{/sha}","trees_url":"https://api.github.com/repos/wagn/wikirate/git/trees{/sha}","statuses_url":"https://api.github.com/repos/wagn/wikirate/statuses/{sha}","languages_url":"https://api.github.com/repos/wagn/wikirate/languages","stargazers_url":"https://api.github.com/repos/wagn/wikirate/stargazers","contributors_url":"https://api.github.com/repos/wagn/wikirate/contributors","subscribers_url":"https://api.github.com/repos/wagn/wikirate/subscribers","subscription_url":"https://api.github.com/repos/wagn/wikirate/subscription","commits_url":"https://api.github.com/repos/wagn/wikirate/commits{/sha}","git_commits_url":"https://api.github.com/repos/wagn/wikirate/git/commits{/sha}","comments_url":"https://api.github.com/repos/wagn/wikirate/comments{/number}","issue_comment_url":"https://api.github.com/repos/wagn/wikirate/issues/comments{/number}","contents_url":"https://api.github.com/repos/wagn/wikirate/contents/{+path}","compare_url":"https://api.github.com/repos/wagn/wikirate/compare/{base}...{head}","merges_url":"https://api.github.com/repos/wagn/wikirate/merges","archive_url":"https://api.github.com/repos/wagn/wikirate/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/wagn/wikirate/downloads","issues_url":"https://api.github.com/repos/wagn/wikirate/issues{/number}","pulls_url":"https://api.github.com/repos/wagn/wikirate/pulls{/number}","milestones_url":"https://api.github.com/repos/wagn/wikirate/milestones{/number}","notifications_url":"https://api.github.com/repos/wagn/wikirate/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/wagn/wikirate/labels{/name}","releases_url":"https://api.github.com/repos/wagn/wikirate/releases{/id}","deployments_url":"https://api.github.com/repos/wagn/wikirate/deployments","created_at":"2014-01-13T22:29:39Z","updated_at":"2016-05-07T04:55:35Z","pushed_at":"2016-09-15T20:54:39Z","git_url":"git://github.com/wagn/wikirate.git","ssh_url":"git@github.com:wagn/wikirate.git","clone_url":"https://github.com/wagn/wikirate.git","svn_url":"https://github.com/wagn/wikirate","homepage":null,"size":99148,"stargazers_count":2,"watchers_count":2,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":5,"mirror_url":null,"open_issues_count":2,"forks":5,"open_issues":2,"watchers":2,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/wagn/wikirate/pulls/494"},"html":{"href":"https://github.com/wagn/wikirate/pull/494"},"issue":{"href":"https://api.github.com/repos/wagn/wikirate/issues/494"},"comments":{"href":"https://api.github.com/repos/wagn/wikirate/issues/494/comments"},"review_comments":{"href":"https://api.github.com/repos/wagn/wikirate/pulls/494/comments"},"review_comment":{"href":"https://api.github.com/repos/wagn/wikirate/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/wagn/wikirate/pulls/494/commits"},"statuses":{"href":"https://api.github.com/repos/wagn/wikirate/statuses/fffc52e7262000d18d239329bbecb981442f0bdb"}}}}
{"actor":{"display_login":"houndci-bot"}}