mirror of
https://github.com/mastodon/mastodon.git
synced 2024-11-16 11:45:19 +00:00
c33931b613
* Fix prev/next links on public profile page * Don't make pagination urls if no available statuses * Fix empty check method * Put left chevron before prev page link * Add scope for pagination "starting at" a given id * Status pagination try 2: s/prev/older and s/next/newer "older" on left, "newer" on right Use new scope for "newer" link Extract magic 20 page size to constant Remove max_id from feed pagination as it's not respected * Reinstate max_id for accounts atom stream * normalize
24 lines
835 B
Ruby
24 lines
835 B
Ruby
# frozen_string_literal: true
|
|
|
|
module Paginable
|
|
extend ActiveSupport::Concern
|
|
|
|
included do
|
|
scope :paginate_by_max_id, ->(limit, max_id = nil, since_id = nil) {
|
|
query = order(arel_table[:id].desc).limit(limit)
|
|
query = query.where(arel_table[:id].lt(max_id)) if max_id.present?
|
|
query = query.where(arel_table[:id].gt(since_id)) if since_id.present?
|
|
query
|
|
}
|
|
|
|
# Differs from :paginate_by_max_id in that it gives the results immediately following min_id,
|
|
# whereas since_id gives the items with largest id, but with since_id as a cutoff.
|
|
# Results will be in ascending order by id.
|
|
scope :paginate_by_min_id, ->(limit, min_id = nil) {
|
|
query = reorder(arel_table[:id]).limit(limit)
|
|
query = query.where(arel_table[:id].gt(min_id)) if min_id.present?
|
|
query
|
|
}
|
|
end
|
|
end
|