Class: Tagging::UpdateSpecialSectionWorker
- Inherits:
-
ApplicationWorker
- Object
- ApplicationWorker
- Tagging::UpdateSpecialSectionWorker
- Defined in:
- app/workers/tagging/update_special_section_worker.rb
Overview
related to app/workers/tagging/remove_tag_special_section_worker.rb
Instance Method Summary collapse
Methods inherited from ApplicationWorker
Instance Method Details
#perform ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/workers/tagging/update_special_section_worker.rb', line 4 def perform restaurant_tag = RestaurantTag.find_by(id: 756) return if restaurant_tag.blank? home_section_restaurants = CompactRestaurant.where.not(rank_section_12: nil) return if home_section_restaurants.blank? restaurant_ids = home_section_restaurants.map do |cr| if cr.branch.present? cr.branch.restaurants.pluck(:id) else cr.restaurant.id end end restaurant_ids = (restaurant_tag.restaurants.pluck(:id) + restaurant_ids).flatten.uniq ActiveRecord::Base.transaction do = RestaurantTagsRestaurant.where(restaurant_tag_id: restaurant_tag.id).where.not(restaurant_id: restaurant_ids) .each do |rtr| rtr.restaurant&.refresh_view_cache_key end .delete_all new_data = restaurant_ids.map do |restaurant_id| Restaurant.fetch(restaurant_id).refresh_view_cache_key RestaurantTagsRestaurant.new(restaurant_tag_id: restaurant_tag.id, restaurant_id: restaurant_id) end RestaurantTagsRestaurant.import new_data, on_duplicate_key_update: %i[restaurant_id restaurant_tag_id], raise_error: true restaurant_tag.touch end end |