From 914f6b411aad140e95c9e80b058a9b332f332693 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Sat, 16 Aug 2025 14:19:55 -0400 Subject: [PATCH] Extract limit methods --- .../api/v1/statuses/contexts_controller.rb | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/app/controllers/api/v1/statuses/contexts_controller.rb b/app/controllers/api/v1/statuses/contexts_controller.rb index 1ea1c5ca55c..a4983d3d923 100644 --- a/app/controllers/api/v1/statuses/contexts_controller.rb +++ b/app/controllers/api/v1/statuses/contexts_controller.rb @@ -20,16 +20,6 @@ class Api::V1::Statuses::ContextsController < Api::BaseController def show cache_if_unauthenticated! - ancestors_limit = CONTEXT_LIMIT - descendants_limit = CONTEXT_LIMIT - descendants_depth_limit = nil - - if current_account.nil? - ancestors_limit = ANCESTORS_LIMIT - descendants_limit = DESCENDANTS_LIMIT - descendants_depth_limit = DESCENDANTS_DEPTH_LIMIT - end - ancestors_results = @status.in_reply_to_id.nil? ? [] : @status.ancestors(ancestors_limit, current_account) descendants_results = @status.descendants(descendants_limit, current_account, descendants_depth_limit) loaded_ancestors = preload_collection(ancestors_results, Status) @@ -57,6 +47,18 @@ class Api::V1::Statuses::ContextsController < Api::BaseController private + def ancestors_limit + current_account.present? ? CONTEXT_LIMIT : ANCESTORS_LIMIT + end + + def descendants_limit + current_account.present? ? CONTEXT_LIMIT : DESCENDANTS_LIMIT + end + + def descendants_depth_limit + current_account.present? ? nil : DESCENDANTS_DEPTH_LIMIT + end + def set_status @status = Status.find(params[:status_id]) authorize @status, :show?