recalculateTotalPrice performance improvements

Created on 10 January 2024, 11 months ago
Updated 23 May 2024, 7 months ago

Currently, the order total will be recalculated many times where a loop is used on the order items, and the OrderItem class addAdjustment() / removeAdjustment() function is used.
So this is a performance issue as it was in the AvailabilityOrderProcessor. See #3127569 .
So I copied the logic used there to solve the problem where these functions are in use.

📌 Task
Status

Closed: won't fix

Version

2.37

Component

Developer experience

Created by

🇷🇸Serbia norbert-goco Subotica

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @norbert-goco
  • Status changed to Needs review 11 months ago
  • 🇮🇱Israel jsacksick

    I guess why not... Code looks a little bit less clean, but I think the changes make sense. I tend to get the storage right before needing it instead of instantiating from the constructor nowadays (so perhaps let's just add an entityTypeManager property to the OrderRefresh) and get the storage right before using it.
    Why not setting the status to "needs review" so we can see if tests are passing?

  • Open in Jenkins → Open on Drupal.org →
    Core: 10.2.x + Environment: PHP 8.1 & MySQL 5.7
    last update 11 months ago
    Patch Failed to Apply
  • 🇮🇱Israel jsacksick

    Oh patch is incorrect.

  • 🇦🇺Australia elc

    I don't believe there should be bypassing of using the API - such as not using addAdjustment or removeItem. This spreads out the functionality instead of keeping it tight and controllable. Large duplication of code having to do the same thing all over the place and then remember to do recalc at the end.

    Instead, should addAdjustment and removeItem be amended to use new addAdjustmentMultiple and removeItemMultiple, which are given an array of items to work with, after which it does the normal thing of $order->recalculateTotalPrice();. Much more in keeping with how it works now.

  • 🇮🇱Israel jsacksick

    You're right, thought about that, the other option would be to add an extra parameter, which defaults to TRUE to not break BC, $recalculate_order_total = TRUE.

  • Status changed to Closed: won't fix 7 months ago
  • 🇮🇱Israel jsacksick

    I've given this a second thought, and decided not to pursue the change as it makes the code harder to grok.

Production build 0.71.5 2024