From f0fff3eb1051ff77ec3f37aa75f8c56720b626a3 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Fri, 28 Sep 2018 02:23:45 +0200 Subject: Support min_id-based pagination in REST API (#8736) * Allow min_id pagination in Feed#get * Add min_id pagination to home and list timeline APIs * Add min_id pagination to account statuses, public and tag APIs * Remove unused stub in reports API * Use min_id pagination in notifications, favourites, and fix order * Fix HomeFeed#from_database not using paginate_by_id --- app/models/concerns/paginable.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'app/models/concerns') diff --git a/app/models/concerns/paginable.rb b/app/models/concerns/paginable.rb index 66695677e..52f186918 100644 --- a/app/models/concerns/paginable.rb +++ b/app/models/concerns/paginable.rb @@ -19,5 +19,13 @@ module Paginable query = query.where(arel_table[:id].gt(min_id)) if min_id.present? query } + + scope :paginate_by_id, ->(limit, **options) { + if options[:min_id].present? + paginate_by_min_id(limit, options[:min_id]).reverse + else + paginate_by_max_id(limit, options[:max_id], options[:since_id]) + end + } end end -- cgit From 6c835085a35d64be2c977b98de07801af5abec72 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Sat, 29 Sep 2018 19:03:33 +0200 Subject: Fix timeline pagination (#8827) Ruby's ** operator does not play well with non-Hash objects, which the params slice is Fix #8821 --- app/models/concerns/paginable.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/models/concerns') diff --git a/app/models/concerns/paginable.rb b/app/models/concerns/paginable.rb index 52f186918..8863094f7 100644 --- a/app/models/concerns/paginable.rb +++ b/app/models/concerns/paginable.rb @@ -20,7 +20,7 @@ module Paginable query } - scope :paginate_by_id, ->(limit, **options) { + scope :paginate_by_id, ->(limit, options = {}) { if options[:min_id].present? paginate_by_min_id(limit, options[:min_id]).reverse else -- cgit