summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Wintermeyer <stefan.wintermeyer@amooma.de>2013-06-25 12:53:13 +0200
committerStefan Wintermeyer <stefan.wintermeyer@amooma.de>2013-06-25 12:53:13 +0200
commit17f94f46374d60e58a00071303c9081469e7997c (patch)
treebeee2985e91e7024e9288e0da7ab1b32d4326884
parenta24aee0fdfcbbc2200ad05ee5b789aec5988f1ad (diff)
Optimized the active_calls method. Much faster now.
Added a dispatchable_incoming_calls method.
-rw-r--r--app/models/switchboard.rb11
1 files changed, 10 insertions, 1 deletions
diff --git a/app/models/switchboard.rb b/app/models/switchboard.rb
index 095f878..73219e8 100644
--- a/app/models/switchboard.rb
+++ b/app/models/switchboard.rb
@@ -25,8 +25,13 @@ class Switchboard < ActiveRecord::Base
}
belongs_to :user, :touch => true
+
has_many :switchboard_entries, :dependent => :destroy
+ has_many :switchable_switchboard_entries, :class_name => "SwitchboardEntry", :conditions => {:switchable => true}
+
has_many :sip_accounts, :through => :switchboard_entries
+ has_many :switchable_sip_accounts, :source => :sip_account, :through => :switchable_switchboard_entries, :uniq => true
+
has_many :phone_numbers, :through => :sip_accounts
before_validation :convert_0_to_nil
@@ -36,7 +41,11 @@ class Switchboard < ActiveRecord::Base
end
def active_calls
- self.switchboard_entries.where(:switchable => true).map{|se| se.sip_account}.uniq.map{|sip_account| sip_account.calls}.flatten
+ Call.where("sip_account_id = ? or b_sip_account_id = ?", self.switchable_sip_account_ids, self.switchable_sip_account_ids)
+ end
+
+ def dispatchable_incoming_calls
+ Call.where("b_sip_account_id = ?", self.switchable_sip_account_ids)
end
private