Skip to content

Commit

Permalink
CV2-5601: apply the background job if the obj exists (#2119)
Browse files Browse the repository at this point in the history
  • Loading branch information
melsawy authored Nov 4, 2024
1 parent aae65fd commit f72b0a8
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions app/lib/check_cached_fields.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,14 @@ def update_cached_field(name, obj, condition, ids, callback, options, event)

def update_cached_field_bg(name, ids, callback, options, klass, id, event)
obj = event == 'destroy' ? klass.constantize : klass.constantize.find_by_id(id)
recalculate = options[:recalculate]
self.where(id: ids).each do |target|
value = callback == :recalculate ? target.send(recalculate) : obj.send(callback, target)
Rails.cache.write(self.check_cache_key(self, target.id, name), value, expires_in: self.cached_field_expiration(options))
# Update ES index and PG, if needed
self.index_and_pg_cached_field(options, value, name, target)
unless obj.nil?
recalculate = options[:recalculate]
self.where(id: ids).each do |target|
value = callback == :recalculate ? target.send(recalculate) : obj.send(callback, target)
Rails.cache.write(self.check_cache_key(self, target.id, name), value, expires_in: self.cached_field_expiration(options))
# Update ES index and PG, if needed
self.index_and_pg_cached_field(options, value, name, target)
end
end
end
end
Expand Down

0 comments on commit f72b0a8

Please sign in to comment.