Class: OnlineMigrations::DataMigrations::BackfillSiteMapRecommendations

Inherits:
OnlineMigrations::DataMigration
  • Object
show all
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

Instance Method Details

#collectionObject



14
15
16
17
18
19
20
# File 'lib/online_migrations/data_migrations/backfill_site_map_recommendations.rb', line 14

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

#countObject



30
31
32
33
34
35
36
# File 'lib/online_migrations/data_migrations/backfill_site_map_recommendations.rb', line 30

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) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/online_migrations/data_migrations/backfill_site_map_recommendations.rb', line 22

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.message}"
  end
end