lib/ecoportal/api/graphql/helpers/locations_tree.rb in ecoportal-api-graphql-0.3.13 vs lib/ecoportal/api/graphql/helpers/locations_tree.rb in ecoportal-api-graphql-0.3.14

- old
+ new

@@ -1,15 +1,15 @@ module Ecoportal module API class GraphQL module Helpers module LocationsTree + RELEVANT_NODES_COUNT = 1000 + def treeify(nodes) - parents = nodes.each_with_object({}) do |node, parents| - parent = node.parent - parentId = parent && parent.id.upcase - (parents[parentId] ||= []).push(node) + parents = nodes.each_with_object({}) do |node, out| + (out[node.parent_id_upcase] ||= []).push(node) end get_children(nil, parents) end private @@ -19,18 +19,18 @@ class_types = child.classifications || [] class_ids = class_types.map(&:id) class_names = class_types.map(&:name) results << { - "id" => child.id, - "name" => child.name, - "weight" => child.weight, - "parent_id" => node_id, - "archived" => child.archived, + "id" => child.id, + "name" => child.name, + "weight" => child.weight, + "parent_id" => node_id, + "archived" => child.archived, "archived_token" => child.archivedToken, "classifications" => class_ids, "classification_names" => class_names, - "nodes" => get_children(child.id, parents).compact + "nodes" => get_children(child.id, parents).compact } end end end end