Revert "Improved history get calls for performance (#192)."

This reverts commit 9e458956c7.
This commit is contained in:
Rolf Schmidt 2016-08-22 11:47:18 +02:00
parent 9e458956c7
commit 0d328e12e5

View file

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