Class: Tagging::RemoveTagSpecialSectionWorker

Inherits:
ApplicationWorker show all
Defined in:
app/workers/tagging/remove_tag_special_section_worker.rb

Overview

This worker is responsible for removing a specific tag (tag id: 756) from a restaurant or group of restaurants and refreshing the view cache key of the affected restaurants. related to app/workers/tagging/update_special_section_worker.rb

Instance Method Summary collapse

Methods inherited from ApplicationWorker

unlimited_retry

Instance Method Details

#perform(compact_restaurant_id) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/workers/tagging/remove_tag_special_section_worker.rb', line 6

def perform(compact_restaurant_id)
  restaurant_tag = RestaurantTag.find_by(id: 756)

  return if restaurant_tag.blank?

  compact_restaurant = CompactRestaurant.find compact_restaurant_id
  restaurant_ids = if compact_restaurant.branch
                     compact_restaurant.branch.restaurants.pluck(:id)
                   else
                     compact_restaurant.restaurant_id
                   end

  tags = RestaurantTagsRestaurant.where(restaurant_tag_id: restaurant_tag.id, restaurant_id: restaurant_ids)

  return if tags.blank?

  tags.each do |rtr|
    rtr.restaurant&.refresh_view_cache_key
  end

  tags.delete_all

  restaurant_tag.touch
end