VRFS-2179 minor refactor of offline notifications to prevent a second loop from executing

This commit is contained in:
Brian Smith 2014-09-13 08:04:40 -04:00
parent d8d987e21f
commit 072f3101c7
2 changed files with 24 additions and 49 deletions

View File

@ -448,7 +448,6 @@ module JamRuby
end
def self.participant_create user, music_session_id, client_id, as_musician, tracks, audio_latency
binding.pry
music_session = MusicSession.find(music_session_id)
if music_session.active_music_session

View File

@ -555,7 +555,6 @@ module JamRuby
# remove anyone in the session and invited musicians
friends_and_followers = friends_and_followers - music_session.unique_users - music_session.invited_musicians
online_ff, offline_ff = [], []
notification_msg = format_msg(NotificationTypes::MUSICIAN_SESSION_JOIN, {:user => user})
friends_and_followers.each do |ff|
@ -580,19 +579,15 @@ module JamRuby
)
@@mq_router.publish_to_user(ff.id, msg)
else
offline_ff << ff
end
end
# send email notifications
if APP_CONFIG.send_join_session_email_notifications
begin
offline_ff.each do |f|
UserMailer.musician_session_join(f, notification_msg, music_session.id).deliver
else
if APP_CONFIG.send_join_session_email_notifications
begin
UserMailer.musician_session_join(ff, notification_msg, music_session.id).deliver
rescue => e
@@log.error("Unable to send MUSICIAN_SESSION_JOIN email to user #{ff.email} #{e}")
end
end
rescue => e
@@log.error("Unable to send MUSICIAN_SESSION_JOIN email to user #{f.email} #{e}")
end
end
end
@ -981,7 +976,6 @@ module JamRuby
# if the session is private, don't send any notifications
if music_session.musician_access || music_session.fan_access
online_followers, offline_followers = [], []
notification_msg = format_msg(NotificationTypes::BAND_SESSION_JOIN, {:band => band})
followers = band.followers.map { |bf| bf.user }
@ -1013,17 +1007,12 @@ module JamRuby
@@mq_router.publish_to_user(follower.id, msg)
else
offline_followers << follower
end
end
# send email notifications
if !offline_followers.empty? && music_session.fan_access && APP_CONFIG.send_join_session_email_notifications
offline_followers.each do |f|
begin
UserMailer.band_session_join(f, notification_msg, music_session.id).deliver
rescue => e
@@log.error("Unable to send BAND_SESSION_JOIN email to user #{f.email} #{e}")
if music_session.fan_access && APP_CONFIG.send_join_session_email_notifications
begin
UserMailer.band_session_join(follower, notification_msg, music_session.id).deliver
rescue => e
@@log.error("Unable to send BAND_SESSION_JOIN email to user #{follower.email} #{e}")
end
end
end
end
@ -1042,7 +1031,6 @@ module JamRuby
follower_users = user_followers.map { |uf| uf.user }
friends_and_followers = friend_users.concat(follower_users).uniq
online_ff, offline_ff = [], []
notification_msg = format_msg(NotificationTypes::MUSICIAN_RECORDING_SAVED, {:user => user})
friends_and_followers.each do |ff|
@ -1065,16 +1053,11 @@ module JamRuby
@@mq_router.publish_to_user(ff.id, notification_msg)
else
offline_ff << ff
end
end
# send email notifications
offline_ff.each do |f|
begin
UserMailer.musician_recording_saved(f, notification_msg).deliver
rescue => e
@@log.error("Unable to send MUSICIAN_RECORDING_SAVED email to user #{f.email} #{e}")
begin
UserMailer.musician_recording_saved(ff, notification_msg).deliver
rescue => e
@@log.error("Unable to send MUSICIAN_RECORDING_SAVED email to user #{ff.email} #{e}")
end
end
end
end
@ -1084,8 +1067,6 @@ module JamRuby
band = recording.band
notification_msg = format_msg(NotificationTypes::BAND_RECORDING_SAVED, {:band => band})
offline_ff = []
band.followers.each do |bf|
follower = bf.user
notification = Notification.new
@ -1105,18 +1086,13 @@ module JamRuby
notification.created_date
)
@@mq_router.publish_to_user(of.id, notification_msg)
@@mq_router.publish_to_user(follower.id, notification_msg)
else
offline_ff << follower
end
end
# send email notifications
offline_ff.each do |f|
begin
UserMailer.band_recording_saved(f, notification_msg).deliver
rescue => e
@@log.error("Unable to send BAND_RECORDING_SAVED email to user #{f.email} #{e}")
begin
UserMailer.band_recording_saved(follower, notification_msg).deliver
rescue => e
@@log.error("Unable to send BAND_RECORDING_SAVED email to user #{follower.email} #{e}")
end
end
end
end