Skip to content

Commit

Permalink
Add pagination limits from outer get method, mimicking Paginable.to_a…
Browse files Browse the repository at this point in the history
…_paginated_by_id
  • Loading branch information
sneakers-the-rat committed Jan 25, 2024
1 parent 7c465c3 commit 538aeb8
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions app/models/public_feed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def get(limit, max_id = nil, since_id = nil, min_id = nil)
scope.merge!(without_local_only_scope) unless allow_local_only?
scope.merge!(without_replies_scope) unless with_replies?
scope.merge!(without_reblogs_scope) unless with_reblogs?
scope.merge!(without_duplicate_reblogs) if with_reblogs?
scope.merge!(without_duplicate_reblogs(limit, max_id, since_id, min_id)) if with_reblogs?
scope.merge!(local_only_scope) if local_only?
scope.merge!(remote_only_scope) if remote_only?
scope.merge!(account_filters_scope) if account?
Expand Down Expand Up @@ -91,9 +91,18 @@ def without_reblogs_scope
Status.without_reblogs
end

def without_duplicate_reblogs
def without_duplicate_reblogs(limit, max_id, since_id, min_id)
inner_query = Status.select('DISTINCT ON (reblog_of_id) statuses.id').reorder(reblog_of_id: :desc, id: :desc)
if min_id.present?
inner_query = inner_query.where(min_id < :id)
elsif since_id.present?
inner_query = inner_query.where(since_id < :id)
end
inner_query = inner_query.where(max_id > :id) if max_id.present?
inner_query = inner_query.limit(limit) if limit.present?

Status.where(statuses: { reblog_of_id: nil })
.or(Status.where(id: Status.select('DISTINCT ON (reblog_of_id) statuses.id').reorder(reblog_of_id: :desc, id: :desc)))
.or(Status.where(id: inner_query))
end

def media_only_scope
Expand Down

0 comments on commit 538aeb8

Please sign in to comment.