From 465ee7792ff48905088efdf3df6f718081b5e244 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Thu, 7 Apr 2022 18:06:15 +0200 Subject: Fix pagination header on empty trends responses in REST API (#17986) --- app/controllers/api/v1/trends/links_controller.rb | 6 +++++- app/controllers/api/v1/trends/statuses_controller.rb | 6 +++++- app/controllers/api/v1/trends/tags_controller.rb | 6 +++++- 3 files changed, 15 insertions(+), 3 deletions(-) (limited to 'app/controllers/api/v1') diff --git a/app/controllers/api/v1/trends/links_controller.rb b/app/controllers/api/v1/trends/links_controller.rb index b1cde5a4b..2385fe438 100644 --- a/app/controllers/api/v1/trends/links_controller.rb +++ b/app/controllers/api/v1/trends/links_controller.rb @@ -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 diff --git a/app/controllers/api/v1/trends/statuses_controller.rb b/app/controllers/api/v1/trends/statuses_controller.rb index 4977803fb..1f2fff582 100644 --- a/app/controllers/api/v1/trends/statuses_controller.rb +++ b/app/controllers/api/v1/trends/statuses_controller.rb @@ -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 diff --git a/app/controllers/api/v1/trends/tags_controller.rb b/app/controllers/api/v1/trends/tags_controller.rb index 329ef5ae7..38003f599 100644 --- a/app/controllers/api/v1/trends/tags_controller.rb +++ b/app/controllers/api/v1/trends/tags_controller.rb @@ -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 -- cgit From 3906dd67ed84f963238f9bdccef63fe3fd3a05aa Mon Sep 17 00:00:00 2001 From: Claire Date: Fri, 8 Apr 2022 19:17:37 +0200 Subject: Fix extremely rare race condition when deleting a toot or account (#17994) --- app/controllers/api/v1/admin/accounts_controller.rb | 3 ++- app/controllers/api/v1/statuses_controller.rb | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) (limited to 'app/controllers/api/v1') diff --git a/app/controllers/api/v1/admin/accounts_controller.rb b/app/controllers/api/v1/admin/accounts_controller.rb index dc9d3402f..65ed69f7b 100644 --- a/app/controllers/api/v1/admin/accounts_controller.rb +++ b/app/controllers/api/v1/admin/accounts_controller.rb @@ -65,8 +65,9 @@ class Api::V1::Admin::AccountsController < Api::BaseController def destroy authorize @account, :destroy? + json = render_to_body json: @account, serializer: REST::Admin::AccountSerializer Admin::AccountDeletionWorker.perform_async(@account.id) - render json: @account, serializer: REST::Admin::AccountSerializer + render json: json end def unsensitive diff --git a/app/controllers/api/v1/statuses_controller.rb b/app/controllers/api/v1/statuses_controller.rb index 3fe137bfd..9270117da 100644 --- a/app/controllers/api/v1/statuses_controller.rb +++ b/app/controllers/api/v1/statuses_controller.rb @@ -77,10 +77,12 @@ class Api::V1::StatusesController < Api::BaseController authorize @status, :destroy? @status.discard - RemovalWorker.perform_async(@status.id, { 'redraft' => true }) @status.account.statuses_count = @status.account.statuses_count - 1 + json = render_to_body json: @status, serializer: REST::StatusSerializer, source_requested: true + + RemovalWorker.perform_async(@status.id, { 'redraft' => true }) - render json: @status, serializer: REST::StatusSerializer, source_requested: true + render json: json end private -- cgit