about summary refs log tree commit diff
path: root/app/models/concerns/status_threading_concern.rb
diff options
context:
space:
mode:
authorDavid Yip <yipdw@member.fsf.org>2018-06-07 05:13:49 -0500
committerDavid Yip <yipdw@member.fsf.org>2018-06-07 05:13:49 -0500
commit8142bd2553e7819722fdfc401e06cb10eeddd230 (patch)
treed771e65a58d3c69ba1c08c3fc145f24b5b806274 /app/models/concerns/status_threading_concern.rb
parentf8d50a40701f344ea7c2a0e5475bbcbc727ef930 (diff)
parent2304d52599bfd3a907931971a94b9b68f229ab0a (diff)
Merge remote-tracking branch 'tootsuite/master' into merge-upstream
  Conflicts:
 	app/models/status.rb

The conflict in the Status model was due to
https://github.com/tootsuite/mastodon/commit/5bf500338478f819a65d25636a0af61a482972d3.
It was resolved by accepting tootsuite's changes.
Diffstat (limited to 'app/models/concerns/status_threading_concern.rb')
-rw-r--r--app/models/concerns/status_threading_concern.rb10
1 files changed, 8 insertions, 2 deletions
diff --git a/app/models/concerns/status_threading_concern.rb b/app/models/concerns/status_threading_concern.rb
index 1ba8fc693..fa441469c 100644
--- a/app/models/concerns/status_threading_concern.rb
+++ b/app/models/concerns/status_threading_concern.rb
@@ -51,12 +51,16 @@ module StatusThreadingConcern
   end
 
   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)
       AS (
         SELECT id, ARRAY[id]
         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
         SELECT statuses.id, path || statuses.id
         FROM search_tree
@@ -68,6 +72,8 @@ module StatusThreadingConcern
       ORDER BY path
       LIMIT :limit
     SQL
+
+    descendants_with_self - [self]
   end
 
   def find_statuses_from_tree_path(ids, account)