|
|
@ -51,12 +51,16 @@ module StatusThreadingConcern |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def descendant_statuses(limit, max_child_id, since_child_id, depth) |
|
|
|
def descendant_statuses(limit, max_child_id, since_child_id, depth) |
|
|
|
Status.find_by_sql([<<-SQL.squish, id: id, limit: limit, max_child_id: max_child_id, since_child_id: since_child_id, depth: depth]) |
|
|
|
# use limit + 1 and depth + 1 because 'self' is included |
|
|
|
|
|
|
|
depth += 1 if depth.present? |
|
|
|
|
|
|
|
limit += 1 if limit.present? |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
descendants_with_self = Status.find_by_sql([<<-SQL.squish, id: id, limit: limit, max_child_id: max_child_id, since_child_id: since_child_id, depth: depth]) |
|
|
|
WITH RECURSIVE search_tree(id, path) |
|
|
|
WITH RECURSIVE search_tree(id, path) |
|
|
|
AS ( |
|
|
|
AS ( |
|
|
|
SELECT id, ARRAY[id] |
|
|
|
SELECT id, ARRAY[id] |
|
|
|
FROM statuses |
|
|
|
FROM statuses |
|
|
|
WHERE in_reply_to_id = :id AND COALESCE(id < :max_child_id, TRUE) AND COALESCE(id > :since_child_id, TRUE) |
|
|
|
WHERE id = :id AND COALESCE(id < :max_child_id, TRUE) AND COALESCE(id > :since_child_id, TRUE) |
|
|
|
UNION ALL |
|
|
|
UNION ALL |
|
|
|
SELECT statuses.id, path || statuses.id |
|
|
|
SELECT statuses.id, path || statuses.id |
|
|
|
FROM search_tree |
|
|
|
FROM search_tree |
|
|
@ -68,6 +72,8 @@ module StatusThreadingConcern |
|
|
|
ORDER BY path |
|
|
|
ORDER BY path |
|
|
|
LIMIT :limit |
|
|
|
LIMIT :limit |
|
|
|
SQL |
|
|
|
SQL |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
descendants_with_self - [self] |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def find_statuses_from_tree_path(ids, account) |
|
|
|
def find_statuses_from_tree_path(ids, account) |
|
|
|