Class: OnlineMigrations::DataMigrations::ReembedInfraredHeatingPanels
- Inherits:
-
OnlineMigrations::DataMigration
- Object
- OnlineMigrations::DataMigration
- OnlineMigrations::DataMigrations::ReembedInfraredHeatingPanels
- Defined in:
- lib/online_migrations/data_migrations/reembed_infrared_heating_panels.rb
Overview
Re-embeds the line items whose names/descriptions changed in the radiant-panel
-> infrared-heating-panels rename, so semantic search stops returning the old
vectors. Enqueues one +EmbeddingWorker+ per item (the embedding itself runs on
the +ai_embeddings+ Sidekiq queue, off the deploy path); batching + the
enqueuing migration's +iteration_pause+ keep that queue from being flooded.
Idempotent: re-running simply re-enqueues, and EmbeddingWorker overwrites the
item's vector with one built from current (clean) content.
Constant Summary collapse
- BATCH_SIZE =
Enqueue is light (one Sidekiq push per item), so a large batch is fine; the
enqueuing migration throttles batches via iteration_pause. 200- SCOPE_SQL =
Line items under the renamed product line.
"primary_pl_path_slugs::text LIKE 'infrared_heating_panels%'"
Instance Method Summary collapse
-
#collection ⇒ ActiveRecord::Batches::BatchEnumerator
Yields batches of line items to re-embed.
-
#count ⇒ Integer
Number of items queued for re-embedding.
-
#process(items) ⇒ void
Enqueues an embedding refresh for each item in the batch.
Instance Method Details
#collection ⇒ ActiveRecord::Batches::BatchEnumerator
Yields batches of line items to re-embed.
30 31 32 |
# File 'lib/online_migrations/data_migrations/reembed_infrared_heating_panels.rb', line 30 def collection Item.where(SCOPE_SQL).in_batches(of: BATCH_SIZE) end |
#count ⇒ Integer
Number of items queued for re-embedding. Used for progress reporting.
49 |
# File 'lib/online_migrations/data_migrations/reembed_infrared_heating_panels.rb', line 49 def count = Item.where(SCOPE_SQL).count |
#process(items) ⇒ void
This method returns an undefined value.
Enqueues an embedding refresh for each item in the batch.
38 39 40 41 42 43 |
# File 'lib/online_migrations/data_migrations/reembed_infrared_heating_panels.rb', line 38 def process(items) items.find_each do |item| chunked = item.respond_to?(:needs_chunking?) && item.needs_chunking? EmbeddingWorker.perform_async('Item', item.id, { 'chunked' => chunked }) end end |