diff options
author | Stefan Wintermeyer <stefan.wintermeyer@amooma.de> | 2013-03-17 12:44:33 +0100 |
---|---|---|
committer | Stefan Wintermeyer <stefan.wintermeyer@amooma.de> | 2013-03-17 12:44:33 +0100 |
commit | 0ed2894ca7371199788c202b61f53a3f73c4b03b (patch) | |
tree | 2526d54ed5b28efe07312ac96895af76e28fb684 /app/controllers/trigger_controller.rb | |
parent | 5ed3837a8688e46a33d3ad3b0eb0343eb1a5ba85 (diff) |
Reduce the push load.
Diffstat (limited to 'app/controllers/trigger_controller.rb')
-rw-r--r-- | app/controllers/trigger_controller.rb | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/app/controllers/trigger_controller.rb b/app/controllers/trigger_controller.rb index a858e33..6b58d6a 100644 --- a/app/controllers/trigger_controller.rb +++ b/app/controllers/trigger_controller.rb @@ -92,19 +92,26 @@ class TriggerController < ApplicationController def sip_account_update sip_account = SipAccount.find(params[:id]) - # TO-DO: Only update the neccessary entries. - # - SwitchboardEntry.all.each do |switchboard_entry| - new_html = ActionController::Base.helpers.escape_javascript(render_to_string("switchboard_entries/_switchboard_entry", :layout => false, :locals => {:switchboard_entry => switchboard_entry})) - PrivatePub.publish_to("/switchboards/#{switchboard_entry.switchboard.id}", "$('#switchboard_entry_id_" + switchboard_entry.id.to_s + "').replaceWith('#{new_html}');") - end + if sip_account.updated_at < Time.now - Switchboard.all.each do |switchboard| - if sip_account.call_legs.where(:sip_account_id => switchboard.user.sip_account_ids).any? || - sip_account.b_call_legs.where(:sip_account_id => switchboard.user.sip_account_ids).any? - new_html = ActionController::Base.helpers.escape_javascript(render_to_string("switchboards/_current_user_dashboard", :layout => false, :locals => {:current_user => switchboard.user})) - PrivatePub.publish_to("/switchboards/#{switchboard.id}", "$('.dashboard').replaceWith('#{new_html}');") + # Push an update to sip_account.switchboard_entries + # + sip_account.switchboard_entries.each do |switchboard_entry| + escaped_switchboard_entry_partial = ActionController::Base.helpers.escape_javascript(render_to_string("switchboard_entries/_switchboard_entry", :layout => false, :locals => {:switchboard_entry => switchboard_entry})) + PrivatePub.publish_to("/switchboards/#{switchboard_entry.switchboard.id}", "$('#switchboard_entry_id_" + switchboard_entry.id.to_s + "').replaceWith('#{escaped_switchboard_entry_partial}');") end + + # Push an update to the needed switchboards + # + Switchboard.where(:user_id => sip_account.sip_accountable.id).each do |switchboard| + if sip_account.call_legs.where(:sip_account_id => switchboard.user.sip_account_ids).any? || + sip_account.b_call_legs.where(:sip_account_id => switchboard.user.sip_account_ids).any? + escaped_switchboard_partial = ActionController::Base.helpers.escape_javascript(render_to_string("switchboards/_current_user_dashboard", :layout => false, :locals => {:current_user => switchboard.user})) + PrivatePub.publish_to("/switchboards/#{switchboard.id}", "$('.dashboard').replaceWith('#{escaped_switchboard_partial}');") + end + end + + sip_account.touch end render( |