GitHub PullRequestReviewCommentEvent at 2014-02-18 21:04:15
Repository: global_registry
Actor: mattdrees
Payload: {"comment":{"url":"https://api.github.com/repos/CruGlobal/global_registry/pulls/comments/9841588","id":9841588,"diff_hunk":"@@ -16,6 +17,63 @@ class Entity < ActiveRecord::Base\n \n   delegate :name, :field_type, to: :entity_type\n \n+  # to appropriately take advantage of the index, we need to query with the same function the index uses.\n+  def self.with_value(desired_value, table_alias = nil)\n+    table_prefix = if table_alias\n+      table_alias + '.'\n+    else\n+      ''\n+    end\n+\n+    value_prefix = desired_value[0, 50]\n+    index_selection = where(\"substring(#{table_prefix}value from 1 for 50) = ?\", value_prefix)\n+    if (desired_value.length > 50)\n+      index_selection.where(\"#{table_prefix}value\" => desired_value)\n+    else\n+      index_selection\n+    end\n+  end\n+\n+  def self.preload_enum_references(entities)\n+    ids = []\n+    entities.each do |entity|\n+      entity.collect_enum_value_ids(ids)\n+    end\n+    if ids.empty?\n+      return\n+    end\n+    values = Array.wrap(Entity.find_with_descendants(ids, also_preload: :entity_type))\n+    index = values.index_by(&:id)\n+    entities.each do |entity|\n+      entity.cache_enum_references(index)\n+    end\n+\n+    preload_enum_references(values)\n+  end\n+\n+  def collect_enum_value_ids(ids)\n+    if field_type == 'enum' && value\n+      ids << value\n+    elsif field_type == 'entity'\n+      children.each { |child| child.collect_enum_value_ids(ids)}","path":"app/models/entity.rb","position":58,"original_position":58,"commit_id":"74458f7a4ad42b4439caa94c69d95692d80ff38d","original_commit_id":"74458f7a4ad42b4439caa94c69d95692d80ff38d","user":{"login":"mattdrees","id":58439,"avatar_url":"https://gravatar.com/avatar/f302731367bdad29fe30ee230da836aa?d=https%3A%2F%2Fidenticons.github.com%2Fa232176a129c157a9e406cabbd1d9bc6.png&r=x","gravatar_id":"f302731367bdad29fe30ee230da836aa","url":"https://api.github.com/users/mattdrees","html_url":"https://github.com/mattdrees","followers_url":"https://api.github.com/users/mattdrees/followers","following_url":"https://api.github.com/users/mattdrees/following{/other_user}","gists_url":"https://api.github.com/users/mattdrees/gists{/gist_id}","starred_url":"https://api.github.com/users/mattdrees/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mattdrees/subscriptions","organizations_url":"https://api.github.com/users/mattdrees/orgs","repos_url":"https://api.github.com/users/mattdrees/repos","events_url":"https://api.github.com/users/mattdrees/events{/privacy}","received_events_url":"https://api.github.com/users/mattdrees/received_events","type":"User","site_admin":false},"body":"So, the method isn't intended to return anything useful.  It modifies the parameter.\r\nI think I did this to avoid creating a bunch of throw-away arrays.\r\nBut it sounds like this is coming at a readability sacrifice, which isn't worth it. I'll change it.","created_at":"2014-02-18T21:04:15Z","updated_at":"2014-02-18T21:04:15Z","html_url":"https://github.com/CruGlobal/global_registry/pull/9#discussion_r9841588","pull_request_url":"https://api.github.com/repos/CruGlobal/global_registry/pulls/9","_links":{"self":{"href":"https://api.github.com/repos/CruGlobal/global_registry/pulls/comments/9841588"},"html":{"href":"https://github.com/CruGlobal/global_registry/pull/9#discussion_r9841588"},"pull_request":{"href":"https://api.github.com/repos/CruGlobal/global_registry/pulls/9"}}}}