Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
With several category rules active and showing a list of products, the number of queries to show a single page quickly balloons to over 1000. This is because the rule requires the terms attached to a given line item+product each time another category rule is applied.
The attached patch statically caches the terms found on a given line item+product combination during a single request. In my case this removed about 900 database queries on a single, uncached page view showing about 15 products, with a few more in the cart.
Comment | File | Size | Author |
---|---|---|---|
#2 | commerce-discount-product-category-cache-build-1.patch | 4.93 KB | fearlsgroove |
Comments
Comment #2
fearlsgroove CreditAttribution: fearlsgroove at Alloy Magnetic commentedOops left a dpm in there.
Comment #3
mglamanThank you! This thought crossed my mind a week ago about how much of a performance suck this thing is. Here's my initial patch review.
Can we utilize drupal_static(__FUNCTION__)?
I like having the option to blow away a static cache elsewhere just in case.
Can you remove this dpm()?
Comment #4
armrus CreditAttribution: armrus at Initlab commentedPlease view another way to caching and fixing performance reduces.
Comment #5
kevster CreditAttribution: kevster commentedI just applied this patch against version 7.1.2 and got the following error showing on every page:
Warning: array_intersect(): Argument #1 is not an array in commerce_discount_product_category_has_specified_terms_build() (line 136 of /var/www/sites/xxxx/html/sites/all/modules/contrib/commerce_discount_product_category/commerce_discount_product_category.rules.inc).
running on:
- drupal 7.69
- commerce 7.11
- php 7.0.33
Will try against the dev version.