def ancestor_ids
Rails.cache.fetch("ancestors:#{id}") do
- ancestors_without_self.pluck(:id)
+ ancestor_statuses.pluck(:id)
end
end
- def ancestors_without_self
- ancestor_statuses - [self]
- end
-
def ancestor_statuses
- Status.find_by_sql([<<-SQL.squish, id: id])
+ Status.find_by_sql([<<-SQL.squish, id: in_reply_to_id])
WITH RECURSIVE search_tree(id, in_reply_to_id, path)
AS (
SELECT id, in_reply_to_id, ARRAY[id]
end
def descendant_ids
- descendants_without_self.pluck(:id)
- end
-
- def descendants_without_self
- descendant_statuses - [self]
+ descendant_statuses.pluck(:id)
end
def descendant_statuses
AS (
SELECT id, ARRAY[id]
FROM statuses
- WHERE id = :id
+ WHERE in_reply_to_id = :id
UNION ALL
SELECT statuses.id, path || statuses.id
FROM search_tree