docbrown/app/workers/reactions/bust_homepage_cache_worker.rb
rhymes 5a2cae4fbb
Rubocop: enable and fix new Rails cops (#9537)
* Enable new Rails/* cops and use autocorrect on them

* Fixed Rails/PluckInWhere leftovers

* Fix Rails/DefaultScope

* Enable and fix Rails/PluckId

* Fix manual mistake with forcing autocorrection on Rails/PluckId

* Apply PR feedback to remove Rails/PluckId inline disables

* Apply PR feedback to get rid of Rails/PluckInWhere inline
2020-07-29 11:14:19 +02:00

22 lines
661 B
Ruby

module Reactions
class BustHomepageCacheWorker
include Sidekiq::Worker
sidekiq_options queue: :high_priority, retry: 10
def perform(reaction_id)
cache_buster = CacheBuster
reaction = Reaction.find_by(id: reaction_id, reactable_type: "Article")
return unless reaction&.reactable
featured_articles_ids = Article.where(featured: true).order(hotness_score: :desc).limit(3).ids
return unless featured_articles_ids.include?(reaction.reactable_id)
reaction.reactable.touch
cache_buster.bust("/")
cache_buster.bust("/")
cache_buster.bust("/?i=i")
cache_buster.bust("?i=i")
end
end
end