From 2c5676a2fcdadbc40d6726e30fe7986f70d9a89b Mon Sep 17 00:00:00 2001 From: mgabdev <> Date: Wed, 13 Jan 2021 14:06:28 -0500 Subject: [PATCH] Updated Explore,Group,GroupCollection timeline controllers unauth result limits MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit • Updated: - Explore,Group,GroupCollection timeline controllers unauth result limits to be max 2 pages (group still empty for now) - Max limit to be 25 (for everything, unless provided default) in BaseController --- app/controllers/api/base_controller.rb | 4 +++- app/controllers/api/v1/timelines/explore_controller.rb | 3 ++- .../api/v1/timelines/group_collection_controller.rb | 3 ++- app/controllers/api/v1/timelines/group_controller.rb | 3 ++- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/app/controllers/api/base_controller.rb b/app/controllers/api/base_controller.rb index 34e552c2..b8817bee 100644 --- a/app/controllers/api/base_controller.rb +++ b/app/controllers/api/base_controller.rb @@ -5,6 +5,8 @@ class Api::BaseController < ApplicationController DEFAULT_ACCOUNTS_LIMIT = 20 DEFAULT_CHAT_CONVERSATION_LIMIT = 100 DEFAULT_CHAT_CONVERSATION_MESSAGE_LIMIT = 20 + MAX_LIMIT_PARAM = 25 + MIN_UNAUTHENTICATED_PAGES = 2 include RateLimitHeaders @@ -55,7 +57,7 @@ class Api::BaseController < ApplicationController def limit_param(default_limit) return default_limit unless params[:limit] - [params[:limit].to_i.abs, default_limit * 2].min + [params[:limit].to_i.abs, MAX_LIMIT_PARAM].min end def params_slice(*keys) diff --git a/app/controllers/api/v1/timelines/explore_controller.rb b/app/controllers/api/v1/timelines/explore_controller.rb index af63c298..fcf69c9a 100644 --- a/app/controllers/api/v1/timelines/explore_controller.rb +++ b/app/controllers/api/v1/timelines/explore_controller.rb @@ -48,7 +48,8 @@ class Api::V1::Timelines::ExploreController < Api::BaseController FeedManager.instance.filter?(:home, status, current_account.id) } else - SortingQueryBuilder.new.call(@sort_type, nil, params[:page]) + page = [params[:page].to_i.abs, MIN_UNAUTHENTICATED_PAGES].min + SortingQueryBuilder.new.call(@sort_type, nil, page) end end diff --git a/app/controllers/api/v1/timelines/group_collection_controller.rb b/app/controllers/api/v1/timelines/group_collection_controller.rb index c52e261f..957e3e35 100644 --- a/app/controllers/api/v1/timelines/group_collection_controller.rb +++ b/app/controllers/api/v1/timelines/group_collection_controller.rb @@ -71,7 +71,8 @@ class Api::V1::Timelines::GroupCollectionController < Api::BaseController FeedManager.instance.filter?(:home, status, current_account.id) } else - SortingQueryBuilder.new.call(@sort_type, @groupIds, params[:page]) + page = [params[:page].to_i.abs, MIN_UNAUTHENTICATED_PAGES].min + SortingQueryBuilder.new.call(@sort_type, @groupIds, page) end end diff --git a/app/controllers/api/v1/timelines/group_controller.rb b/app/controllers/api/v1/timelines/group_controller.rb index defb7bf3..764669b6 100644 --- a/app/controllers/api/v1/timelines/group_controller.rb +++ b/app/controllers/api/v1/timelines/group_controller.rb @@ -55,7 +55,8 @@ class Api::V1::Timelines::GroupController < Api::BaseController } else return [] - # SortingQueryBuilder.new.call(@sort_type, @group, params[:page]) + # page = [params[:page].to_i.abs, MIN_UNAUTHENTICATED_PAGES].min + # SortingQueryBuilder.new.call(@sort_type, @group, page) end end