]> cat aescling's git repositories - mastodon.git/commitdiff
Fix pagination header on empty trends responses in REST API (#17986)
authorEugen Rochko <eugen@zeonfederated.com>
Thu, 7 Apr 2022 16:06:15 +0000 (18:06 +0200)
committerGitHub <noreply@github.com>
Thu, 7 Apr 2022 16:06:15 +0000 (18:06 +0200)
app/controllers/api/v1/trends/links_controller.rb
app/controllers/api/v1/trends/statuses_controller.rb
app/controllers/api/v1/trends/tags_controller.rb
app/models/trends/query.rb

index b1cde5a4bb72e49c56d9f3d2c03da7178b8740c4..2385fe4380d2aeda06dffaa3ac5c05bf199f4aa7 100644 (file)
@@ -36,13 +36,17 @@ class Api::V1::Trends::LinksController < Api::BaseController
   end
 
   def next_path
-    api_v1_trends_links_url pagination_params(offset: offset_param + limit_param(DEFAULT_LINKS_LIMIT))
+    api_v1_trends_links_url pagination_params(offset: offset_param + limit_param(DEFAULT_LINKS_LIMIT)) if records_continue?
   end
 
   def prev_path
     api_v1_trends_links_url pagination_params(offset: offset_param - limit_param(DEFAULT_LINKS_LIMIT)) if offset_param > limit_param(DEFAULT_LINKS_LIMIT)
   end
 
+  def records_continue?
+    @links.size == limit_param(DEFAULT_LINKS_LIMIT)
+  end
+
   def offset_param
     params[:offset].to_i
   end
index 4977803fbd82114398d233d4a398524e43b6a781..1f2fff582de4eb73539c2fa1872c71332511ff14 100644 (file)
@@ -36,7 +36,7 @@ class Api::V1::Trends::StatusesController < Api::BaseController
   end
 
   def next_path
-    api_v1_trends_statuses_url pagination_params(offset: offset_param + limit_param(DEFAULT_STATUSES_LIMIT))
+    api_v1_trends_statuses_url pagination_params(offset: offset_param + limit_param(DEFAULT_STATUSES_LIMIT)) if records_continue?
   end
 
   def prev_path
@@ -46,4 +46,8 @@ class Api::V1::Trends::StatusesController < Api::BaseController
   def offset_param
     params[:offset].to_i
   end
+
+  def records_continue?
+    @statuses.size == limit_param(DEFAULT_STATUSES_LIMIT)
+  end
 end
index 329ef5ae73c5db4c483195787b5281af14e1c0f2..38003f599afb990d713c76216e24b4055848c53a 100644 (file)
@@ -32,7 +32,7 @@ class Api::V1::Trends::TagsController < Api::BaseController
   end
 
   def next_path
-    api_v1_trends_tags_url pagination_params(offset: offset_param + limit_param(DEFAULT_TAGS_LIMIT))
+    api_v1_trends_tags_url pagination_params(offset: offset_param + limit_param(DEFAULT_TAGS_LIMIT)) if records_continue?
   end
 
   def prev_path
@@ -42,4 +42,8 @@ class Api::V1::Trends::TagsController < Api::BaseController
   def offset_param
     params[:offset].to_i
   end
+
+  def records_continue?
+    @tags.size == limit_param(DEFAULT_TAGS_LIMIT)
+  end
 end
index 231b652288ac0df5b707d31344b5137dd6a0b56d..f19df162f844640869407e1c4ae6983b002b0baf 100644 (file)
@@ -59,7 +59,7 @@ class Trends::Query
     @records
   end
 
-  delegate :each, :empty?, :first, :last, to: :records
+  delegate :each, :empty?, :first, :last, :size, to: :records
 
   def to_ary
     records.dup