Story #105846070 - update existing record if present

This commit is contained in:
Matt Farnsworth 2015-12-14 13:04:46 +02:00
parent 352c748258
commit 23d4547e2b

View file

@ -48,11 +48,16 @@ class BusinessRegistryCache < ActiveRecord::Base
cache = BusinessRegistryCache.find_by(ident: ident_code, ident_country_code: ident_cc) cache = BusinessRegistryCache.find_by(ident: ident_code, ident_country_code: ident_cc)
# fetch new data if cache is expired # fetch new data if cache is expired
return cache if cache.present? && cache.retrieved_on > (Time.zone.now - Setting.days_to_keep_business_registry_cache.days) return cache if cache.present? && cache.retrieved_on > (Time.zone.now - Setting.days_to_keep_business_registry_cache.days)
cache = [] # expired data is forbidden businesses = business_registry.associated_businesses(ident_code, ident_cc)
data = business_registry.associated_businesses(ident_code, ident_cc) unless businesses.nil?
unless data.nil? if cache.blank?
cache = BusinessRegistryCache.new(data) cache = BusinessRegistryCache.new(businesses)
else
cache.update businesses
end
cache.save cache.save
else
cache = [] # expired data is forbidden
end end
cache cache
end end