Class: OnlineMigrations::DataMigrations::BackfillSiteMapRecommendations
- Inherits:
-
OnlineMigrations::DataMigration
- Object
- OnlineMigrations::DataMigration
- OnlineMigrations::DataMigrations::BackfillSiteMapRecommendations
- Defined in:
- lib/online_migrations/data_migrations/backfill_site_map_recommendations.rb
Overview
Backfills SiteMapRecommendation records from existing seo_report JSONB data.
Runs Seo::RecommendationExtractorService for each SiteMap that has a report
but no recommendations yet.
Enqueued by: 20260314055949_enqueue_backfill_site_map_recommendations.rb
Constant Summary collapse
- BATCH_SIZE =
Batch size.
50
Instance Method Summary collapse
-
#collection ⇒ ActiveRecord::Batches::BatchEnumerator
Batches of SiteMaps without recommendations.
-
#count ⇒ Integer
Number of SiteMaps without recommendations.
-
#process(site_maps) ⇒ void
Extracts recommendations per site map.
Instance Method Details
#collection ⇒ ActiveRecord::Batches::BatchEnumerator
Returns batches of SiteMaps without recommendations.
15 16 17 18 19 20 21 |
# File 'lib/online_migrations/data_migrations/backfill_site_map_recommendations.rb', line 15 def collection SiteMap .where.not(seo_report: nil) .where.not(seo_report: {}) .where.not(id: SiteMapRecommendation.select(:site_map_id)) .in_batches(of: BATCH_SIZE) end |
#count ⇒ Integer
Returns number of SiteMaps without recommendations.
33 34 35 36 37 38 39 |
# File 'lib/online_migrations/data_migrations/backfill_site_map_recommendations.rb', line 33 def count SiteMap .where.not(seo_report: nil) .where.not(seo_report: {}) .where.not(id: SiteMapRecommendation.select(:site_map_id)) .count end |
#process(site_maps) ⇒ void
This method returns an undefined value.
Returns extracts recommendations per site map.
24 25 26 27 28 29 30 |
# File 'lib/online_migrations/data_migrations/backfill_site_map_recommendations.rb', line 24 def process(site_maps) site_maps.each do |site_map| Seo::RecommendationExtractorService.new(site_map: site_map).process rescue StandardError => e Rails.logger.warn "[BackfillSiteMapRecommendations] Error for SiteMap #{site_map.id}: #{e.}" end end |