Commit b11e1190317737da76e080077033a8eb9559535a

Authored by Daniela Feitosa
Committed by Antonio Terceiro
1 parent 7060c597

NotifyJob executes sql to be faster

(ActionItem1703)
Showing 1 changed file with 6 additions and 10 deletions   Show diff stats
lib/notify_activity_to_profiles_job.rb
@@ -12,21 +12,17 @@ class NotifyActivityToProfilesJob < Struct.new(:tracked_action_id) @@ -12,21 +12,17 @@ class NotifyActivityToProfilesJob < Struct.new(:tracked_action_id)
12 tracked_action = ActionTracker::Record.find(tracked_action_id) 12 tracked_action = ActionTracker::Record.find(tracked_action_id)
13 target = tracked_action.target 13 target = tracked_action.target
14 if target.is_a?(Community) && NOTIFY_ONLY_COMMUNITY.include?(tracked_action.verb) 14 if target.is_a?(Community) && NOTIFY_ONLY_COMMUNITY.include?(tracked_action.verb)
15 - ActionTrackerNotification.create(:action_tracker => tracked_action, :profile => target) 15 + ActionTrackerNotification.connection.execute("insert into action_tracker_notifications(profile_id, action_tracker_id) values (#{target.id}, #{tracked_action.id})")
16 return 16 return
17 end 17 end
18 18
19 - ActionTrackerNotification.create(:action_tracker => tracked_action, :profile => tracked_action.user)  
20 - tracked_action.user.each_friend do |friend|  
21 - ActionTrackerNotification.create(:action_tracker => tracked_action, :profile => friend)  
22 - end 19 + ActionTrackerNotification.connection.execute("insert into action_tracker_notifications(profile_id, action_tracker_id) values (#{tracked_action.user.id}, #{tracked_action.id})")
  20 + ActionTrackerNotification.connection.execute("insert into action_tracker_notifications(profile_id, action_tracker_id) select friend_id, #{tracked_action_id} from friendships where person_id=#{tracked_action.user.id}")
23 21
24 if target.is_a?(Community) 22 if target.is_a?(Community)
25 - target.each_member do |member|  
26 - next if member == tracked_action.user  
27 - ActionTrackerNotification.create(:action_tracker => tracked_action, :profile => member)  
28 - end  
29 - ActionTrackerNotification.create(:action_tracker => tracked_action, :profile => target) unless NOT_NOTIFY_COMMUNITY.include?(tracked_action.verb) 23 + ActionTrackerNotification.connection.execute("insert into action_tracker_notifications(profile_id, action_tracker_id) select distinct profiles.id, #{tracked_action_id} from role_assignments, profiles where profiles.type = 'Person' and profiles.id = role_assignments.accessor_id and profiles.id != #{tracked_action.user.id} and role_assignments.resource_type = 'Profile' and role_assignments.resource_id = #{target.id}")
  24 +
  25 + ActionTrackerNotification.connection.execute("insert into action_tracker_notifications(profile_id, action_tracker_id) values (#{target.id}, #{tracked_action_id})") unless NOT_NOTIFY_COMMUNITY.include?(tracked_action.verb)
30 end 26 end
31 end 27 end
32 end 28 end