Class: Decidim::FindAndUpdateDescendantsJob
- Inherits:
-
ApplicationJob
- Object
- ActiveJob::Base
- ApplicationJob
- Decidim::FindAndUpdateDescendantsJob
- Defined in:
- app/jobs/decidim/find_and_update_descendants_job.rb
Overview
Update search indexes for each descendants of a given element
Constant Summary collapse
- MAX_DEPTH =
5
Instance Method Summary collapse
Instance Method Details
#perform(element, current_depth = 0) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'app/jobs/decidim/find_and_update_descendants_job.rb', line 9 def perform(element, current_depth = 0) if current_depth >= MAX_DEPTH Rails.logger.warn "Max depth of #{MAX_DEPTH} reached for element #{element.class.name} with id #{element.id}. Stopping recursion." return end descendants_collector = components_for(element) descendants_collector << element.comments.to_a if element.respond_to?(:comments) return if descendants_collector.blank? descendants_collector.each do |descendants| next if descendants.blank? Decidim::UpdateSearchIndexesJob.perform_later(descendants, current_depth + 1) end end |