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

#collectionActiveRecord::Batches::BatchEnumerator

Returns batches of SiteMaps without recommendations.

Returns:

  • (ActiveRecord::Batches::BatchEnumerator)

    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

#countInteger

Returns number of SiteMaps without recommendations.

Returns:

  • (Integer)

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