Create variant links through Rails association

This allows us to delay saving to the db, reducing overall queries.
This commit is contained in:
David Cook
2026-04-01 10:39:18 +11:00
parent 734af38386
commit 05f0e71545
2 changed files with 28 additions and 71 deletions

View File

@@ -56,10 +56,10 @@ module Spree
target_variant: [mapped_variants.keys])
# Link the new variants
variant_links.find_each do |variant_link|
VariantLink.create(
source_variant: mapped_variants[variant_link.source_variant],
target_variant: mapped_variants[variant_link.target_variant]
)
source_variant = mapped_variants[variant_link.source_variant]
target_variant = mapped_variants[variant_link.target_variant]
target_variant.variant_links_as_target.new(source_variant:)
end
end

View File

@@ -101,85 +101,42 @@ RSpec.describe Spree::Core::ProductDuplicator do
"VariantLink Load",
"Spree::Variant Load",
"Spree::Variant Load",
"TRANSACTION",
"Spree::ShippingCategory Load",
"Spree::Product Load",
"Spree::Taxon Load",
"Enterprise Load",
"Spree::Variant Create",
"Spree::Price Create",
"Spree::StockItem Exists?",
"Spree::StockItem Exists?",
"Spree::StockItem Create",
"ActsAsTaggableOn::Tagging Load",
"Spree::Variant Update",
"Spree::ShippingCategory Load",
"Spree::Product Load",
"Spree::Taxon Load",
"Enterprise Load",
"Spree::Variant Create",
"Spree::Price Create",
"Spree::StockItem Exists?",
"Spree::StockItem Exists?",
"Spree::StockItem Create",
"ActsAsTaggableOn::Tagging Load",
"Spree::Variant Update",
"VariantLink Create",
"Spree::Product Update",
"Spree::Variant Exists?",
"Spree::Variant Load",
"Enterprise Load",
"Enterprise Update",
"Enterprise Update All",
"Spree::Taxon Update",
"Enterprise Update",
"Enterprise Update All",
"TRANSACTION",
"Spree::Variant Load",
"Spree::Variant Load",
"TRANSACTION",
"Spree::ShippingCategory Load",
"Spree::Product Load",
"Spree::Taxon Load",
"Enterprise Load",
"Spree::Variant Create",
"Spree::Price Create",
"Spree::StockItem Exists?",
"Spree::StockItem Exists?",
"Spree::StockItem Create",
"ActsAsTaggableOn::Tagging Load",
"Spree::Variant Update",
"VariantLink Create",
"Spree::Product Update",
"Spree::Variant Exists?",
"Spree::Variant Load",
"Spree::ShippingCategory Load",
"Spree::Taxon Load",
"Enterprise Load",
"Spree::ShippingCategory Load",
"Spree::Taxon Load",
"Enterprise Load",
"Enterprise Update",
"Enterprise Update All",
"Spree::Taxon Update",
"Enterprise Update",
"Enterprise Update All",
"TRANSACTION",
"TRANSACTION",
"Spree::Product Create",
"Spree::Variant Update",
"Spree::StockItem Load",
"Spree::Variant Create",
"Spree::Price Create",
"Spree::StockItem Exists?",
"Spree::Product Load",
"Spree::Variant Update",
"Spree::StockItem Load",
"Spree::StockItem Exists?",
"Spree::Product Load",
"Spree::StockItem Create",
"ActsAsTaggableOn::Tagging Load",
"Spree::Variant Update",
"Spree::StockItem Load",
"Spree::Variant Create",
"Spree::Price Create",
"VariantLink Create",
"Spree::StockItem Exists?",
"Spree::Product Load",
"Spree::Product Update",
"Spree::Variant Exists?",
"Spree::Variant Load",
"Enterprise Load",
"Enterprise Update",
"Enterprise Update All",
"Spree::StockItem Exists?",
"Spree::StockItem Create",
"ActsAsTaggableOn::Tagging Load",
"Spree::Variant Update",
"Spree::Variant Create",
"Spree::Price Create",
"VariantLink Create",
"Spree::StockItem Exists?",
"Spree::StockItem Exists?",
"Spree::StockItem Create",
"ActsAsTaggableOn::Tagging Load",
"Spree::Variant Update",
"Spree::Product Update",
"Enterprise Update",
"Enterprise Update All",