Class: OnlineMigrations::DataMigrations::DelocalizeBlogEmbedLinks
- Inherits:
-
OnlineMigrations::DataMigration
- Object
- OnlineMigrations::DataMigration
- OnlineMigrations::DataMigrations::DelocalizeBlogEmbedLinks
- Defined in:
- lib/online_migrations/data_migrations/delocalize_blog_embed_links.rb
Overview
Idempotent — Oembed::EmbedLinkDelocalizer leaves already-{{locale}}
links (and external / CDN links) untouched, so healed rows incur a no-op
pass and contribute no DB writes.
update_columns is intentional: it skips update_revised_at /
publish_content_updated_event, so this system rewrite doesn't look like
a content edit to downstream consumers (SEO recrawl, content-updated
subscribers). Mirrors RewriteLegacyFaClassesInArticles.
Heals blog posts whose oEmbed blocks baked a concrete locale into their
internal links — chiefly the unroutable bare /en/... fabricated when
Oembed::ContentRefreshService re-rendered an embed under the
framework-default :en locale, plus any hard-coded /en-US/ / /en-CA/
left by older refreshes.
Rewrites those links back to the {{locale}} placeholder via
Oembed::EmbedLinkDelocalizer — the same transform the now-fixed
ContentRefreshService applies after every refresh — so each post body
once again:
- passes
Blog::ContentRules#internal_links_use_locale_placeholder
(i.e. is saveable throughedit_blog_post), and - resolves to the correct per-market locale at display.
Constant Summary collapse
- BATCH_SIZE =
Solution bodies are large, so keep batches small.
100- INTERNAL_LINK_LOCALE_REGEX =
Postgres POSIX regex matching a hard-coded locale segment inside an
internal WarmlyYours link attribute — relative (href="/en/…",
href="/en-US/…") or absolute (href="https://www.warmlyyours.com/en-US/…"),
on bothhrefand formaction. Deliberately anchored to the attribute
so it does NOT match the concrete/en-US/canonical URLs inside JSON-LD
<script>blocks (those are correct and must stay), nor external links
that merely carry/en/in their own path (e.g.renoassistance.ca/en/…).
The delocalizer rewrites exactly these forms, so the candidate set tracks
the rows actually healed. Editorial-only matches still no-op (the
delocalizer touches links inside oEmbed containers only). '(href|action)="(/|https?://www\.warmlyyours\.com/)(en-US|en-CA|fr-CA|en)/'- OEMBED_MARKER_SQL =
SQL OR-chain matching a post body that carries any oEmbed marker.
<<~SQL.squish solution LIKE '%data-wy-oembed%' OR solution LIKE '%wy-product-embed%' OR solution LIKE '%wy-faq-embed%' OR solution LIKE '%wy-video-embed%' OR solution LIKE '%wy-image-embed%' SQL
Delegated Instance Attributes collapse
-
#count ⇒ Integer
Total candidate rows the SQL pre-filter selects, for progress reporting.
Instance Method Summary collapse
-
#collection ⇒ ActiveRecord::Batches::BatchEnumerator
Yields batches of candidate Posts.
-
#process(posts) ⇒ void
Heals every post in the batch in place.
Instance Method Details
#collection ⇒ ActiveRecord::Batches::BatchEnumerator
Yields batches of candidate Posts.
57 58 59 |
# File 'lib/online_migrations/data_migrations/delocalize_blog_embed_links.rb', line 57 def collection candidate_relation.in_batches(of: BATCH_SIZE) end |
#count ⇒ Integer
Total candidate rows the SQL pre-filter selects, for progress reporting.
76 |
# File 'lib/online_migrations/data_migrations/delocalize_blog_embed_links.rb', line 76 delegate :count, to: :candidate_relation |
#process(posts) ⇒ void
This method returns an undefined value.
Heals every post in the batch in place. Already-canonical rows incur a
no-op pass (no DB write).
67 68 69 |
# File 'lib/online_migrations/data_migrations/delocalize_blog_embed_links.rb', line 67 def process(posts) posts.each { |post| heal(post) } end |