Improved history get calls for performance (#192).
This commit is contained in:
parent
6655485649
commit
9e458956c7
1 changed files with 24 additions and 19 deletions
|
@ -84,7 +84,7 @@ returns
|
|||
}
|
||||
config.hours = hours
|
||||
if !hours || hours.empty?
|
||||
raise "No congifure hours found in calendar #{calendar.inspect}"
|
||||
raise "No configured hours found in calendar #{calendar.inspect}"
|
||||
end
|
||||
|
||||
# get holidays
|
||||
|
@ -103,15 +103,18 @@ returns
|
|||
config.time_zone = calendar.timezone
|
||||
end
|
||||
|
||||
# get history data
|
||||
history_data = history_get
|
||||
|
||||
# fist response
|
||||
# calculate first response escalation
|
||||
if sla.first_response_time
|
||||
self.first_response_escal_date = destination_time(created_at, sla.first_response_time, biz)
|
||||
self.first_response_escal_date = destination_time(created_at, sla.first_response_time, biz, history_data)
|
||||
end
|
||||
|
||||
# get response time in min
|
||||
if first_response
|
||||
self.first_response_in_min = pending_minutes(created_at, first_response, biz, 'business_minutes')
|
||||
self.first_response_in_min = pending_minutes(created_at, first_response, biz, 'business_minutes', history_data)
|
||||
else
|
||||
self.escalation_time = first_response_escal_date
|
||||
end
|
||||
|
@ -135,7 +138,7 @@ returns
|
|||
last_update = last_contact_customer
|
||||
end
|
||||
if sla.update_time && last_update
|
||||
self.update_time_escal_date = destination_time(last_update, sla.update_time, biz)
|
||||
self.update_time_escal_date = destination_time(last_update, sla.update_time, biz, history_data)
|
||||
end
|
||||
if update_time_escal_date && ((!escalation_time && update_time_escal_date) || update_time_escal_date < escalation_time)
|
||||
self.escalation_time = update_time_escal_date
|
||||
|
@ -143,7 +146,7 @@ returns
|
|||
|
||||
# get update time in min
|
||||
if last_update && last_update != created_at
|
||||
self.update_time_in_min = pending_minutes(created_at, last_update, biz, 'business_minutes')
|
||||
self.update_time_in_min = pending_minutes(created_at, last_update, biz, 'business_minutes', history_data)
|
||||
end
|
||||
|
||||
# set sla time
|
||||
|
@ -154,12 +157,12 @@ returns
|
|||
# close time
|
||||
# calculate close time escalation
|
||||
if sla.solution_time
|
||||
self.close_time_escal_date = destination_time(created_at, sla.solution_time, biz)
|
||||
self.close_time_escal_date = destination_time(created_at, sla.solution_time, biz, history_data)
|
||||
end
|
||||
|
||||
# get close time in min
|
||||
if close_time
|
||||
self.close_time_in_min = pending_minutes(created_at, close_time, biz, 'business_minutes')
|
||||
self.close_time_in_min = pending_minutes(created_at, close_time, biz, 'business_minutes', history_data)
|
||||
elsif close_time_escal_date && ((!escalation_time && close_time_escal_date) || close_time_escal_date < escalation_time)
|
||||
self.escalation_time = close_time_escal_date
|
||||
end
|
||||
|
@ -220,7 +223,7 @@ returns
|
|||
|
||||
return destination_time for time range
|
||||
|
||||
destination_time = destination_time(start_time, move_minutes, biz)
|
||||
destination_time = destination_time(start_time, move_minutes, biz, history_data)
|
||||
|
||||
returns
|
||||
|
||||
|
@ -228,7 +231,7 @@ returns
|
|||
|
||||
=end
|
||||
|
||||
def destination_time(start_time, move_minutes, biz)
|
||||
def destination_time(start_time, move_minutes, biz, history_data)
|
||||
destination_time = biz.time(move_minutes, :minutes).after(start_time)
|
||||
|
||||
# go step by step to end of pending_minutes until pending_minutes is 0
|
||||
|
@ -236,7 +239,7 @@ returns
|
|||
500.times.each {
|
||||
|
||||
# check if we have pending time in the range to the destination time
|
||||
pending_minutes = pending_minutes(pending_start_time, destination_time, biz)
|
||||
pending_minutes = pending_minutes(pending_start_time, destination_time, biz, history_data)
|
||||
|
||||
# skip if no pending time is given
|
||||
break if !pending_minutes || pending_minutes <= 0
|
||||
|
@ -252,7 +255,7 @@ returns
|
|||
# get business minutes of pending time
|
||||
# type = business_minutes (pending time in business minutes)
|
||||
# type = non_business_minutes (pending time in non business minutes)
|
||||
def pending_minutes(start_time, end_time, biz, type = 'non_business_minutes')
|
||||
def pending_minutes(start_time, end_time, biz, type = 'non_business_minutes', history_data)
|
||||
|
||||
working_time_in_min = 0
|
||||
total_time_in_min = 0
|
||||
|
@ -264,21 +267,23 @@ returns
|
|||
ignore_escalation: true,
|
||||
).map(&:name)
|
||||
|
||||
history_get.each { |history_item|
|
||||
history_data.each { |history_item|
|
||||
|
||||
# ignore if it isn't a state change
|
||||
next if !history_item['attribute']
|
||||
next if history_item['attribute'] != 'state'
|
||||
|
||||
created_at = history_item['created_at']
|
||||
|
||||
# ignore all newer state before start_time
|
||||
next if history_item['created_at'] < start_time
|
||||
next if created_at < start_time
|
||||
|
||||
# ignore all older state changes after end_time
|
||||
next if last_state_change && last_state_change > end_time
|
||||
|
||||
# if created_at is later then end_time, use end_time as last time
|
||||
if history_item['created_at'] > end_time
|
||||
history_item['created_at'] = end_time
|
||||
if created_at > end_time
|
||||
created_at = end_time
|
||||
end
|
||||
|
||||
# get initial state and time
|
||||
|
@ -293,12 +298,12 @@ returns
|
|||
counted = false
|
||||
end
|
||||
|
||||
diff = biz.within(last_state_change, history_item['created_at']).in_minutes
|
||||
diff = biz.within(last_state_change, created_at).in_minutes
|
||||
if counted
|
||||
# puts "Diff count #{history_item['value_from']} -> #{history_item['value_to']} / #{last_state_change} -> #{history_item['created_at']}"
|
||||
# puts "Diff count #{history_item['value_from']} -> #{history_item['value_to']} / #{last_state_change} -> #{created_at}"
|
||||
working_time_in_min = working_time_in_min + diff
|
||||
# else
|
||||
# puts "Diff not count #{history_item['value_from']} -> #{history_item['value_to']} / #{last_state_change} -> #{history_item['created_at']}"
|
||||
# puts "Diff not count #{history_item['value_from']} -> #{history_item['value_to']} / #{last_state_change} -> #{created_at}"
|
||||
end
|
||||
total_time_in_min = total_time_in_min + diff
|
||||
|
||||
|
@ -309,7 +314,7 @@ returns
|
|||
|
||||
# remember for next loop last state
|
||||
last_state = history_item['value_to']
|
||||
last_state_change = history_item['created_at']
|
||||
last_state_change = created_at
|
||||
}
|
||||
|
||||
# if last state isnt pending, count rest
|
||||
|
|
Loading…
Reference in a new issue