solidus icon indicating copy to clipboard operation
solidus copied to clipboard

Problem with performance of updating line items in cart

Open d-obuchowski opened this issue 3 years ago • 5 comments

Background: User has a lot of line items in shopping cart with different quantity. He didn't do anythings for long time. In meantimes the price or the quantity of some product was changed by customer support. He returned to the shopping cart. The system refreshes all items from shopping cart. - Here we have problem with performance of refreshing.

Code:

  line_items.each do |line_item|
      variant = line_item.variant
      order.contents.add(variant, 0, { price: variant.price }) if line_item.price != variant.price
      stock_quantity = variant.stock_items.first.count_on_hand
      if stock_quantity.zero?
        order.contents.remove_line_item(line_item)
      elsif line_item.quantity > stock_quantity
        difference = line_item.quantity - stock_quantity
        order.contents.remove(variant, difference)
      end
    end

We have situations when refreshing of cart totals 3 minutes ... Any ideas how we can resolve it ?

Solidus Version: 2.11.2

d-obuchowski avatar Nov 05 '21 10:11 d-obuchowski

@d-obuchowski thanks for reporting, where does the code that you posted live? Is it something into Solidus or something that you have customized in your application?

kennyadsl avatar Nov 05 '21 11:11 kennyadsl

@d-obuchowski thanks for reporting, where does the code that you posted live? Is it something into Solidus or something that you have customized in your application?

It is custom code.

d-obuchowski avatar Nov 05 '21 11:11 d-obuchowski

Not sure, but shouldn't order.recalculate do the trick?

waiting-for-dev avatar Nov 08 '21 11:11 waiting-for-dev

I found that the problem is connected mainly with this line: Spree::PromotionHandler::Cart.new(order).activate - it is very time consuming line ;/

d-obuchowski avatar Nov 10 '21 15:11 d-obuchowski

@d-obuchowski FYI check also this discussion, I think it may be related to your issues.

spaghetticode avatar Nov 10 '21 15:11 spaghetticode