Fixes #3550 - CTI Log performance bad because of reformatting of the phone number.
This commit is contained in:
parent
be64e3ff0c
commit
be115dbb5c
8 changed files with 105 additions and 25 deletions
|
@ -73,6 +73,30 @@ class Form extends App.Controller
|
||||||
autofocus: false
|
autofocus: false
|
||||||
)
|
)
|
||||||
|
|
||||||
|
configure_attributes = [
|
||||||
|
{
|
||||||
|
name: 'view_limit',
|
||||||
|
display: '',
|
||||||
|
tag: 'select',
|
||||||
|
null: false,
|
||||||
|
options: [
|
||||||
|
{ name: 60, value: 60 }
|
||||||
|
{ name: 120, value: 120 }
|
||||||
|
{ name: 180, value: 180 }
|
||||||
|
{ name: 240, value: 240 }
|
||||||
|
{ name: 300, value: 300 }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
]
|
||||||
|
new App.ControllerForm(
|
||||||
|
el: @$('.js-viewLimit')
|
||||||
|
model:
|
||||||
|
configure_attributes: configure_attributes,
|
||||||
|
params:
|
||||||
|
view_limit: @config['view_limit']
|
||||||
|
autofocus: false
|
||||||
|
)
|
||||||
|
|
||||||
for row in @config.notify_map
|
for row in @config.notify_map
|
||||||
configure_attributes = [
|
configure_attributes = [
|
||||||
{ name: 'user_ids', display: '', tag: 'column_select', multiple: true, null: true, relation: 'User', sortBy: 'firstname' },
|
{ name: 'user_ids', display: '', tag: 'column_select', multiple: true, null: true, relation: 'User', sortBy: 'firstname' },
|
||||||
|
@ -94,6 +118,10 @@ class Form extends App.Controller
|
||||||
default_caller_id = @$('input[name=default_caller_id]').val()
|
default_caller_id = @$('input[name=default_caller_id]').val()
|
||||||
config.outbound.default_caller_id = cleanupInput(default_caller_id)
|
config.outbound.default_caller_id = cleanupInput(default_caller_id)
|
||||||
|
|
||||||
|
# default view limit
|
||||||
|
view_limit = @$('select[name=view_limit]').val()
|
||||||
|
config.view_limit = parseInt(view_limit)
|
||||||
|
|
||||||
# routing table
|
# routing table
|
||||||
config.outbound.routing_table = []
|
config.outbound.routing_table = []
|
||||||
@$('.js-outboundRouting .js-row').each(->
|
@$('.js-outboundRouting .js-row').each(->
|
||||||
|
|
|
@ -76,19 +76,22 @@
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<p><%- @T('Default caller id.') %>
|
<p><%- @T('Settings') %>
|
||||||
|
|
||||||
<div class="settings-entry">
|
<div class="settings-entry">
|
||||||
<table class="settings-list" style="width: 100%;">
|
<table class="settings-list" style="width: 100%;">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th width="50%"><%- @T('Default caller id') %>
|
<th width="50%"><%- @T('Name') %>
|
||||||
<th width="50%"><%- @T('Note') %>
|
<th width="50%"><%- @T('Description') %>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
<td class="settings-list-control-cell"><input name="default_caller_id" value="<%= @config.outbound.default_caller_id %>" placeholder="4930609854189" class="form-control form-control--small js-summary">
|
<td class="settings-list-control-cell"><input name="default_caller_id" value="<%= @config.outbound.default_caller_id %>" placeholder="4930609854189" class="form-control form-control--small js-summary">
|
||||||
<td class="settings-list-row-control"><%- @T('Default caller id for outbound calls.') %>
|
<td class="settings-list-row-control"><%- @T('Default caller id for outbound calls.') %>
|
||||||
|
<tr>
|
||||||
|
<td class="settings-list-control-cell js-viewLimit">
|
||||||
|
<td class="settings-list-row-control"><%- @T('Shown records in caller log.') %>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -4,10 +4,12 @@ module Cti
|
||||||
|
|
||||||
self.table_name = 'cti_logs'
|
self.table_name = 'cti_logs'
|
||||||
|
|
||||||
store :preferences
|
store :preferences, accessors: %i[from_pretty to_pretty]
|
||||||
|
|
||||||
validates :state, format: { with: /\A(newCall|answer|hangup)\z/, message: 'newCall|answer|hangup is allowed' }
|
validates :state, format: { with: /\A(newCall|answer|hangup)\z/, message: 'newCall|answer|hangup is allowed' }
|
||||||
|
|
||||||
|
before_create :set_pretty
|
||||||
|
before_update :set_pretty
|
||||||
after_commit :push_caller_list_update
|
after_commit :push_caller_list_update
|
||||||
|
|
||||||
=begin
|
=begin
|
||||||
|
@ -327,10 +329,10 @@ returns
|
||||||
def self.log_records(current_user)
|
def self.log_records(current_user)
|
||||||
cti_config = Setting.get('cti_config')
|
cti_config = Setting.get('cti_config')
|
||||||
if cti_config[:notify_map].present?
|
if cti_config[:notify_map].present?
|
||||||
return Cti::Log.where(queue: queues_of_user(current_user, cti_config)).order(created_at: :desc).limit(60)
|
return Cti::Log.where(queue: queues_of_user(current_user, cti_config)).order(created_at: :desc).limit(view_limit)
|
||||||
end
|
end
|
||||||
|
|
||||||
Cti::Log.order(created_at: :desc).limit(60)
|
Cti::Log.order(created_at: :desc).limit(view_limit)
|
||||||
end
|
end
|
||||||
|
|
||||||
=begin
|
=begin
|
||||||
|
@ -448,7 +450,7 @@ Cti::Log.process(
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.push_caller_list_update?(record)
|
def self.push_caller_list_update?(record)
|
||||||
list_ids = Cti::Log.order(created_at: :desc).limit(60).pluck(:id)
|
list_ids = Cti::Log.order(created_at: :desc).limit(view_limit).pluck(:id)
|
||||||
return true if list_ids.include?(record.id)
|
return true if list_ids.include?(record.id)
|
||||||
|
|
||||||
false
|
false
|
||||||
|
@ -490,6 +492,10 @@ optional you can put the max oldest chat entries as argument
|
||||||
# adds virtual attributes when rendering #to_json
|
# adds virtual attributes when rendering #to_json
|
||||||
# see http://api.rubyonrails.org/classes/ActiveModel/Serialization.html
|
# see http://api.rubyonrails.org/classes/ActiveModel/Serialization.html
|
||||||
def attributes
|
def attributes
|
||||||
|
if !from_pretty || !to_pretty
|
||||||
|
set_pretty
|
||||||
|
end
|
||||||
|
|
||||||
virtual_attributes = {
|
virtual_attributes = {
|
||||||
'from_pretty' => from_pretty,
|
'from_pretty' => from_pretty,
|
||||||
'to_pretty' => to_pretty,
|
'to_pretty' => to_pretty,
|
||||||
|
@ -498,14 +504,11 @@ optional you can put the max oldest chat entries as argument
|
||||||
super.merge(virtual_attributes)
|
super.merge(virtual_attributes)
|
||||||
end
|
end
|
||||||
|
|
||||||
def from_pretty
|
def set_pretty
|
||||||
parsed = TelephoneNumber.parse(from&.sub(/^\+?/, '+'))
|
%i[from to].each do |field|
|
||||||
parsed.send(parsed.valid? ? :international_number : :original_number)
|
parsed = TelephoneNumber.parse(send(field)&.sub(/^\+?/, '+'))
|
||||||
|
preferences[:"#{field}_pretty"] = parsed.send(parsed.valid? ? :international_number : :original_number)
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_pretty
|
|
||||||
parsed = TelephoneNumber.parse(to&.sub(/^\+?/, '+'))
|
|
||||||
parsed.send(parsed.valid? ? :international_number : :original_number)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
=begin
|
=begin
|
||||||
|
@ -556,5 +559,8 @@ return best customer id of caller log
|
||||||
customer_id
|
customer_id
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.view_limit
|
||||||
|
Hash(Setting.get('cti_config'))['view_limit'] || 60
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
12
db/migrate/20210510092410_issue_3550_set_pretty.rb
Normal file
12
db/migrate/20210510092410_issue_3550_set_pretty.rb
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
class Issue3550SetPretty < ActiveRecord::Migration[5.2]
|
||||||
|
def change
|
||||||
|
return if !Setting.exists?(name: 'system_init_done')
|
||||||
|
|
||||||
|
Cti::Log.order(created_at: :desc).limit(300).find_each do |log|
|
||||||
|
log.set_pretty
|
||||||
|
log.save!
|
||||||
|
rescue
|
||||||
|
Rails.logger.error "Issue3550SetPretty: Failed to migrate id #{log.id} with from '#{log.from}' and to '#{log.to}'"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
19
spec/db/migrate/issue_3550_set_pretty_spec.rb
Normal file
19
spec/db/migrate/issue_3550_set_pretty_spec.rb
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe Issue3550SetPretty, type: :db_migration, db_strategy: :reset do
|
||||||
|
context 'when cti gets migrated to stored pretty values' do
|
||||||
|
let!(:cti) { create(:'cti/log') }
|
||||||
|
|
||||||
|
before do
|
||||||
|
migrate
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'has from_pretty' do
|
||||||
|
expect(cti.preferences[:from_pretty]).to eq('+49 30 609854180')
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'has to_pretty' do
|
||||||
|
expect(cti.preferences[:to_pretty]).to eq('+49 30 609811111')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -3,7 +3,7 @@ require 'rails_helper'
|
||||||
RSpec.describe UpdateCtiLogsByCallerJob, type: :job do
|
RSpec.describe UpdateCtiLogsByCallerJob, type: :job do
|
||||||
let(:phone) { '1234567890' }
|
let(:phone) { '1234567890' }
|
||||||
let!(:logs) { create_list(:cti_log, 5, direction: :in, from: phone) }
|
let!(:logs) { create_list(:cti_log, 5, direction: :in, from: phone) }
|
||||||
let(:log_prefs) { logs.each(&:reload).map(&:preferences) }
|
let(:log_prefs) { logs.each(&:reload).map { |log| log.preferences[:from] } }
|
||||||
|
|
||||||
it 'accepts a phone number' do
|
it 'accepts a phone number' do
|
||||||
expect { described_class.perform_now(phone) }
|
expect { described_class.perform_now(phone) }
|
||||||
|
@ -14,7 +14,7 @@ RSpec.describe UpdateCtiLogsByCallerJob, type: :job do
|
||||||
it 'updates Cti::Logs from that number with "preferences" => {}' do
|
it 'updates Cti::Logs from that number with "preferences" => {}' do
|
||||||
described_class.perform_now(phone)
|
described_class.perform_now(phone)
|
||||||
|
|
||||||
expect(log_prefs).to all(be_empty)
|
expect(log_prefs).to eq(Array.new(5) { nil })
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ RSpec.describe UpdateCtiLogsByCallerJob, type: :job do
|
||||||
it 'updates Cti::Logs from that number with valid "preferences" hash' do
|
it 'updates Cti::Logs from that number with valid "preferences" hash' do
|
||||||
described_class.perform_now(phone)
|
described_class.perform_now(phone)
|
||||||
|
|
||||||
expect(log_prefs).to all(include('from' => a_kind_of(Array)))
|
expect(log_prefs).not_to eq(Array.new(5) { nil })
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -11,6 +11,18 @@ RSpec.describe Cti::Log do
|
||||||
expect(described_class.log(user)).to match(hash_including(:list, :assets))
|
expect(described_class.log(user)).to match(hash_including(:list, :assets))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when pretty is not generated' do
|
||||||
|
let(:log) { create(:'cti/log') }
|
||||||
|
|
||||||
|
before do
|
||||||
|
log.update_column(:preferences, nil)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'does fallback generate the pretty value' do
|
||||||
|
expect(log.reload.attributes['from_pretty']).to eq('+49 30 609854180')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context 'when over 60 Log records exist' do
|
context 'when over 60 Log records exist' do
|
||||||
subject!(:cti_logs) do
|
subject!(:cti_logs) do
|
||||||
61.times.map do |_i| # rubocop:disable Performance/TimesMap
|
61.times.map do |_i| # rubocop:disable Performance/TimesMap
|
||||||
|
|
|
@ -1296,8 +1296,8 @@ RSpec.describe User, type: :model do
|
||||||
user.update(phone: '0123456789')
|
user.update(phone: '0123456789')
|
||||||
Observer::Transaction.commit
|
Observer::Transaction.commit
|
||||||
Scheduler.worker(true)
|
Scheduler.worker(true)
|
||||||
end.to change { logs.map(&:reload).map(&:preferences) }
|
end.to change { logs.map(&:reload).map { |log| log.preferences[:from] } }
|
||||||
.to(Array.new(5) { {} })
|
.to(Array.new(5) { nil })
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1307,8 +1307,8 @@ RSpec.describe User, type: :model do
|
||||||
user.update(phone: '')
|
user.update(phone: '')
|
||||||
Observer::Transaction.commit
|
Observer::Transaction.commit
|
||||||
Scheduler.worker(true)
|
Scheduler.worker(true)
|
||||||
end.to change { logs.map(&:reload).map(&:preferences) }
|
end.to change { logs.map(&:reload).map { |log| log.preferences[:from] } }
|
||||||
.to(Array.new(5) { {} })
|
.to(Array.new(5) { nil })
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1318,8 +1318,8 @@ RSpec.describe User, type: :model do
|
||||||
user.update(phone: nil)
|
user.update(phone: nil)
|
||||||
Observer::Transaction.commit
|
Observer::Transaction.commit
|
||||||
Scheduler.worker(true)
|
Scheduler.worker(true)
|
||||||
end.to change { logs.map(&:reload).map(&:preferences) }
|
end.to change { logs.map(&:reload).map { |log| log.preferences[:from] } }
|
||||||
.to(Array.new(5) { {} })
|
.to(Array.new(5) { nil })
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue