Improving Inventory Units Creation in Solidus

Reading Time: 2 minutes

To keep track of the right inventory, Solidus needs to create one inventory unit record for every single item being sold. Although each one of them represents a physical item, its design also supports backorderable ones. Learn how to improve Inventory Unit Creation in Solidus to speed up the checkout process.

 

Backorderable inventory units

The concept of backorderable means that the product can still be sold even though it has no units on hand.

The concept of backorderable when working with Solidus Inventory Units means that the product can still be sold even though it has no units on hand. Share on X

If that’s the case, Solidus will create a new inventory unit record but with a backorderable state. So, whenever a new restock happens, they will take all pending inventory units and prepare the shipment.

Some performance issues may happen

One specific problem with this implementation is that it can easily create some performance issues. If the store is —let’s say— a warehouse, they will usually sell large quantities of the same item in the same order. That means that Solidus will need to create one record for every single one of them.

Having large orders in Solidus might cause some performance issues. But no worry, you can solve them by looking at this → https://34.136.44.183/?p=6239 Share on X

Everything happens when Solidus tries to build all packages needed to prepare the shipments. Solidus has the built-in functionality to make sure it creates all packages needed to fulfill the order based on different rules, for example: if one item is in one stock location and the rest in other one, different shipping method by products, and this specific scenario happens in this specific method in the order model.


def create_proposed_shipments
  if completed?
    raise CannotRebuildShipments.new(I18n.t('spree.cannot_rebuild_shipments_order_completed'))
  elsif shipments.any? { |shipment| !shipment.pending? }
    raise CannotRebuildShipments.new(I18n.t('spree.cannot_rebuild_shipments_shipments_not_pending'))
  else
    shipments.destroy_all
    self.shipments = Spree::Config.stock.coordinator_class.new(self).shipments
  end
end

Solidus uses the stock coordinator class to build everything needed, but all objects are not persisted yet. When that assignation happens, Rails persists them in the database, then assigns the relationships to the order. This is where the performance issue might appear, it needs to insert every single record one by one.

How to improve performance?

One thing you can try to improve the performance is to use a new method in Rails 6 that inserts bulk multiple records in a single query. But as discussed here: https://github.com/solidusio/solidus/pull/3392, it is not always beneficial to every store, and it could create more bottlenecks than savings.

Having performance issues building shipments for large orders in Solidus? One thing you can try to improve the performance is to use a new method in Rails 6 that inserts bulk multiple records in a single query. Share on X

If you ever need to improve the performance of inventory unit creation, this is the place to start looking. Or you can give us a call and we will gladly help you improve the performance of your Solidus store.

Thanks for reading!

 
@EdwinCruz, CTO at MagmaLabs

0 Shares:
You May Also Like