Skip to content
Snippets Groups Projects
Commit d6de7534 authored by Marcela Ribeiro de Oliveira's avatar Marcela Ribeiro de Oliveira
Browse files

feed query optimized

parent c082543e
No related branches found
No related tags found
No related merge requests found
class V1::FeedController < ApplicationController class V1::FeedController < ApplicationController
include ::Paginator include ::Paginator
include ActivitiesFilterService
before_action :authenticate_user! before_action :authenticate_user!
# GET v1/feed # GET v1/feed
...@@ -13,11 +14,23 @@ class V1::FeedController < ApplicationController ...@@ -13,11 +14,23 @@ class V1::FeedController < ApplicationController
private private
def activities_followed def activities_followed
activities = [] query = ""
values = [""]
current_user.watching.each do |watching| 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 end
activities
values[0] = query[0..-3]
PublicActivity::Activity.where(key: activities_filter).where(values).order(created_at: :desc)
end end
end end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment