From d6de753402e50e92482599b383e3dd9208ac2ef6 Mon Sep 17 00:00:00 2001 From: Marcela Ribeiro de Oliveira <mro15@inf.ufpr.br> Date: Fri, 30 Jun 2017 09:30:38 -0300 Subject: [PATCH] feed query optimized --- app/controllers/v1/feed_controller.rb | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/app/controllers/v1/feed_controller.rb b/app/controllers/v1/feed_controller.rb index cd1aeb11..36547446 100644 --- a/app/controllers/v1/feed_controller.rb +++ b/app/controllers/v1/feed_controller.rb @@ -1,5 +1,6 @@ class V1::FeedController < ApplicationController include ::Paginator + include ActivitiesFilterService before_action :authenticate_user! # GET v1/feed @@ -13,11 +14,23 @@ class V1::FeedController < ApplicationController private def activities_followed - activities = [] + query = "" + values = [""] + current_user.watching.each do |watching| - activities.push(*watching.activities_filtered.to_a) + if !watching.respond_to?(:state) || watching.state == "published" + query += " (trackable_type = ? and trackable_id = ?) or (owner_type = ? and owner_id = ?) or (recipient_type = ? and recipient_id = ?) or" + values << watching.class.to_s + values << watching.id + values << watching.class.to_s + values << watching.id + values << watching.class.to_s + values << watching.id + end end - activities + + values[0] = query[0..-3] + PublicActivity::Activity.where(key: activities_filter).where(values).order(created_at: :desc) end end -- GitLab