diff --git a/app/models/sla.rb b/app/models/sla.rb index 8e47028b8..7f6911674 100644 --- a/app/models/sla.rb +++ b/app/models/sla.rb @@ -1,3 +1,5 @@ +require 'cache' + class Sla < ApplicationModel store :condition store :data @@ -9,6 +11,7 @@ class Sla < ApplicationModel private def escalation_calculation_rebuild + Cache.delete( 'SLA::List::Active' ) Ticket.escalation_calculation_rebuild end end \ No newline at end of file diff --git a/app/models/ticket.rb b/app/models/ticket.rb index 2eb797d91..5e2302e4f 100644 --- a/app/models/ticket.rb +++ b/app/models/ticket.rb @@ -1,4 +1,6 @@ require 'time_calculation' +require 'sla' + class Ticket < ApplicationModel before_create :number_generate, :check_defaults before_update :check_defaults @@ -478,7 +480,12 @@ class Ticket < ApplicationModel def _escalation_calculation_get_sla sla_selected = nil - Sla.where( :active => true ).each {|sla| + sla_list = Cache.get( 'SLA::List::Active' ) + if sla_list == nil + sla_list = Sla.where( :active => true ).all + Cache.write( 'SLA::List::Active', sla_list, { :expires_in => 1.hour } ) + end + sla_list.each {|sla| if !sla.condition || sla.condition.empty? sla_selected = sla elsif sla.condition