Class: Maintenance::VariantGroupBackfill
- Inherits:
-
Object
- Object
- Maintenance::VariantGroupBackfill
- Defined in:
- app/services/maintenance/variant_group_backfill.rb
Overview
Seeds the canonical VariantGroup layer from the two persisted grouping
mechanisms that predate it (Phase 1 of
doc/tasks/202607051428_VARIANT_GROUPING_UNIFICATION.md):
- Amazon — the
legacy_amazon_variationsbackup table (via
LegacyAmazonVariation) grouped by parentsku(NA marketplaces
share one parent SKU, so US/CA/MX rows of the same family collapse into
one VariantGroup); every variation row is linked viavariant_group_id
and the members come from the variations' items. - Wayfair —
catalog_itemsin the Wayfair catalogs grouped by their
mirroredwayfair_display_sku(families with more than one member).
An item already claimed by a group is never re-claimed (item_id is
globally unique across memberships), so overlapping sources merge into the
first-seen family: if a Wayfair display-SKU group shares any member with an
Amazon-seeded family, the remaining Wayfair members join that family instead
of forming a duplicate.
Idempotent — re-running skips existing groups/members. Dry-run by default.
Defined Under Namespace
Classes: Result
Constant Summary collapse
- WAYFAIR_CATALOG_IDS =
Wayfair catalogs to read mirrored display-SKU families from (US, CA).
CatalogConstants::WAYFAIR_CATALOGS
Instance Method Summary collapse
-
#call ⇒ Result
Runs both seeds (Amazon first — it carries the richer family identity).
-
#initialize(dry_run: true) ⇒ VariantGroupBackfill
constructor
A new instance of VariantGroupBackfill.
Constructor Details
#initialize(dry_run: true) ⇒ VariantGroupBackfill
Returns a new instance of VariantGroupBackfill.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'app/services/maintenance/variant_group_backfill.rb', line 45 def initialize(dry_run: true) @dry_run = dry_run @groups_created = 0 @members_added = 0 @variations_linked = 0 @skipped = [] @log = [] # Item ids already claimed by a family — pre-loaded once (kills the # per-item exists? round trips) and maintained in memory so a dry-run # previews exactly what a real run would do across both seed sources. @claimed_item_ids = VariantGroupMember.pluck(:item_id).to_set # item_id => group (nil in dry-run) for overlap-merges within one run. @groups_by_claimed_item = {} end |
Instance Method Details
#call ⇒ Result
Runs both seeds (Amazon first — it carries the richer family identity).
62 63 64 65 66 67 |
# File 'app/services/maintenance/variant_group_backfill.rb', line 62 def call backfill_from_amazon_variations backfill_from_wayfair_display_skus Result.new(groups_created: @groups_created, members_added: @members_added, variations_linked: @variations_linked, skipped: @skipped, log: @log) end |