Skip to content
Permalink
Browse files

removed benchmarking methods

  • Loading branch information...
dhoss committed Nov 6, 2014
1 parent 4759454 commit 8e4c0f885ee2d0c5612022a818877c452645c22f
Showing with 0 additions and 29 deletions.
  1. +0 −29 lib/treeify.rb
@@ -22,7 +22,6 @@ module Treeify
class_attribute :cols
scope :roots, -> { where(parent_id: nil) }
scope :tree_for, ->(instance) { self.find_by_sql self.tree_sql_for(instance) }
scope :tree_for2, ->(instance) { where("#{table_name}.id IN (#{tree_sql_for2(instance)})").order("#{table_name}.id") }
scope :tree_for_ancestors, ->(instance) { self.find_by_sql self.tree_sql_for_ancestors(instance) }
end

@@ -79,32 +78,12 @@ def tree_sql(instance)
)"
end

def tree_sql2(instance)
"WITH RECURSIVE cte (id, path) AS (
SELECT id,
array[id] AS path
FROM #{table_name}
WHERE id = #{instance.id}
UNION ALL
SELECT #{table_name}.id,
cte.path || #{table_name}.id
FROM #{table_name}
JOIN cte ON #{table_name}.parent_id = cte.id
)"
end

def tree_sql_for(instance)
"#{tree_sql(instance)}
SELECT * FROM cte
ORDER BY path"
end

def tree_sql_for2(instance)
"#{tree_sql2(instance)}
SELECT id FROM cte
ORDER BY path"
end

def tree_sql_for_ancestors(instance)
"#{tree_sql(instance)}
SELECT * FROM cte
@@ -116,10 +95,6 @@ def descendents
self_and_descendents - [self]
end

def descendents2
self_and_descendents2 - [self]
end

def ancestors
self.class.tree_for_ancestors(self)
end
@@ -128,10 +103,6 @@ def self_and_descendents
self.class.tree_for(self)
end

def self_and_descendents2
self.class.tree_for2(self)
end

def is_root?
self.parent_id != nil
end

0 comments on commit 8e4c0f8

Please sign in to comment.
You can’t perform that action at this time.