about summary refs log tree commit diff
path: root/app/controllers/tags_controller.rb
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2020-09-07 11:02:04 +0200
committerGitHub <noreply@github.com>2020-09-07 11:02:04 +0200
commite8bc187845b78e4a94894c69ecf930a524ad2056 (patch)
tree5d406773ebc580f361996222bd636bdaac108b2b /app/controllers/tags_controller.rb
parenta6121a159c5305ea9faa95743a50babb23ab41cd (diff)
Refactor how public and tag timelines are queried (#14728)
Diffstat (limited to 'app/controllers/tags_controller.rb')
-rw-r--r--app/controllers/tags_controller.rb31
1 files changed, 16 insertions, 15 deletions
diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb
index 6426a7d69..6616ba107 100644
--- a/app/controllers/tags_controller.rb
+++ b/app/controllers/tags_controller.rb
@@ -10,8 +10,9 @@ class TagsController < ApplicationController
 
   before_action :require_signature!, if: -> { request.format == :json && authorized_fetch_mode? }
   before_action :authenticate_user!, if: :whitelist_mode?
-  before_action :set_tag
   before_action :set_local
+  before_action :set_tag
+  before_action :set_statuses
   before_action :set_body_classes
   before_action :set_instance_presenter
 
@@ -25,20 +26,11 @@ class TagsController < ApplicationController
 
       format.rss do
         expires_in 0, public: true
-
-        limit     = params[:limit].present? ? [params[:limit].to_i, PAGE_SIZE_MAX].min : PAGE_SIZE
-        @statuses = HashtagQueryService.new.call(@tag, filter_params, nil, @local).limit(limit)
-        @statuses = cache_collection(@statuses, Status)
-
         render xml: RSS::TagSerializer.render(@tag, @statuses)
       end
 
       format.json do
         expires_in 3.minutes, public: public_fetch_mode?
-
-        @statuses = HashtagQueryService.new.call(@tag, filter_params, current_account, @local).paginate_by_max_id(PAGE_SIZE, params[:max_id])
-        @statuses = cache_collection(@statuses, Status)
-
         render json: collection_presenter, serializer: ActivityPub::CollectionSerializer, adapter: ActivityPub::Adapter, content_type: 'application/activity+json'
       end
     end
@@ -54,6 +46,15 @@ class TagsController < ApplicationController
     @local = truthy_param?(:local)
   end
 
+  def set_statuses
+    case request.format&.to_sym
+    when :json
+      @statuses = cache_collection(TagFeed.new(@tag, current_account, local: @local).get(PAGE_SIZE, params[:max_id], params[:since_id], params[:min_id]), Status)
+    when :rss
+      @statuses = cache_collection(TagFeed.new(@tag, nil, local: @local).get(limit_param), Status)
+    end
+  end
+
   def set_body_classes
     @body_classes = 'with-modals'
   end
@@ -62,16 +63,16 @@ class TagsController < ApplicationController
     @instance_presenter = InstancePresenter.new
   end
 
+  def limit_param
+    params[:limit].present? ? [params[:limit].to_i, PAGE_SIZE_MAX].min : PAGE_SIZE
+  end
+
   def collection_presenter
     ActivityPub::CollectionPresenter.new(
-      id: tag_url(@tag, filter_params),
+      id: tag_url(@tag),
       type: :ordered,
       size: @tag.statuses.count,
       items: @statuses.map { |s| ActivityPub::TagManager.instance.uri_for(s) }
     )
   end
-
-  def filter_params
-    params.slice(:any, :all, :none).permit(:any, :all, :none)
-  end
 end