Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance improvements on package generation #550

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions core/app/models/spree/stock/coordinator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,8 @@ def build_location_configured_packages(packages = Array.new)
#
# Returns an array of Package instances
def build_packages(packages = Array.new)
StockLocation.active.each do |stock_location|
stock_locations_with_requested_variants.each do |stock_location|
units_for_location = unallocated_inventory_units.select { |unit| stock_location.stock_item(unit.variant) }
next unless units_for_location.any?
packer = build_packer(stock_location, units_for_location)
packages += packer.packages
end
Expand All @@ -70,6 +69,15 @@ def unallocated_inventory_units
inventory_units - @preallocated_inventory_units
end

def stock_locations_with_requested_variants
Spree::StockLocation.active.joins(:stock_items).
where(spree_stock_items: { variant_id: unallocated_variant_ids }).uniq
end

def unallocated_variant_ids
unallocated_inventory_units.map(&:variant_id).uniq
end

def prioritize_packages(packages)
prioritizer = Prioritizer.new(inventory_units, packages)
prioritizer.prioritized_packages
Expand Down