mirror of https://github.com/tootsuite/mastodon
Exclude status itself from context query (#7083)
ancestor_statuses and descendant_statuses used to include the root status itself, but the behavior is confusing because the root status is not an ancestor nor descendant.pull/7084/head
parent
0893b16695
commit
498327b2e3
|
@ -15,16 +15,12 @@ module StatusThreadingConcern
|
||||||
|
|
||||||
def ancestor_ids
|
def ancestor_ids
|
||||||
Rails.cache.fetch("ancestors:#{id}") do
|
Rails.cache.fetch("ancestors:#{id}") do
|
||||||
ancestors_without_self.pluck(:id)
|
ancestor_statuses.pluck(:id)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def ancestors_without_self
|
|
||||||
ancestor_statuses - [self]
|
|
||||||
end
|
|
||||||
|
|
||||||
def ancestor_statuses
|
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)
|
WITH RECURSIVE search_tree(id, in_reply_to_id, path)
|
||||||
AS (
|
AS (
|
||||||
SELECT id, in_reply_to_id, ARRAY[id]
|
SELECT id, in_reply_to_id, ARRAY[id]
|
||||||
|
@ -43,11 +39,7 @@ module StatusThreadingConcern
|
||||||
end
|
end
|
||||||
|
|
||||||
def descendant_ids
|
def descendant_ids
|
||||||
descendants_without_self.pluck(:id)
|
descendant_statuses.pluck(:id)
|
||||||
end
|
|
||||||
|
|
||||||
def descendants_without_self
|
|
||||||
descendant_statuses - [self]
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def descendant_statuses
|
def descendant_statuses
|
||||||
|
@ -56,7 +48,7 @@ module StatusThreadingConcern
|
||||||
AS (
|
AS (
|
||||||
SELECT id, ARRAY[id]
|
SELECT id, ARRAY[id]
|
||||||
FROM statuses
|
FROM statuses
|
||||||
WHERE id = :id
|
WHERE in_reply_to_id = :id
|
||||||
UNION ALL
|
UNION ALL
|
||||||
SELECT statuses.id, path || statuses.id
|
SELECT statuses.id, path || statuses.id
|
||||||
FROM search_tree
|
FROM search_tree
|
||||||
|
|
Loading…
Reference in New Issue