Skip to content

Commit

Permalink
removed benchmarking methods
Browse files Browse the repository at this point in the history
  • Loading branch information
dhoss committed Nov 6, 2014
1 parent 4759454 commit 8e4c0f8
Showing 1 changed file with 0 additions and 29 deletions.
29 changes: 0 additions & 29 deletions lib/treeify.rb
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 8e4c0f8

Please sign in to comment.