function uc_cart_update_item_object is called when a user hits 'checkout' or 'udpate' and it loops through all cart items calling hook_update_cart_item. This in turn fires uc_product_update_cart_item multiple times and every time it calls uc_cart_get_contents(NULL, 'rebuild'), rebuilding the static cart contents which is trying to be built.

We have a product kit with 45 products in it and when we go to checkout we get WSOD and find that about 500 node loads were run because the static cart cache keeps getting cleaned out. The cart should not be rebuilt multiple times.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Anonymous’s picture

Status: Active » Needs review
FileSize
5.17 KB

and here is a patch.

the high level description is, just rebuild things once, not per item, otherwise we end up with as many node-loads as your memory limit can handle, then WSOD.

rszrama’s picture

Issue tags: +ubercamp sprint
cha0s’s picture

Well done. I did reroll the patch though since the final bit of context didn't match, and it wouldn't apply.

rszrama’s picture

Version: 6.x-2.0-rc3 » 6.x-2.0-rc6
Assigned: Unassigned » rszrama
Issue tags: +Release blocker
rszrama’s picture

I'm really not sure what to make of this patch. I'm having a hard time specifically reconciling justinrandell's high level description with the fact that it simply seems to be sprinkling cache flushes about in various parts of the code. Is anyone using either of these patches live?

Anonymous’s picture

its not just additions - its a removal of the rebuild from uc_product_update_cart_item. that rebuild was *very, very, very ... * expensive, and in fact recursive in some cases, when adding items to a cart.

so the extra rebuilds in code actually lead to substantially less calls at runtime, because we try to rebuild the whole cart when it changes, rather than rebuild it for each item added.

make any more sense now?

rszrama’s picture

I believe so. That was my hunch.

So, you're taking the cart rebuild out of a loop and moving it to the functions that would be responsible for actually altering cart contents? Is it actually necessary, in fact, to put it all over the place? Or can we just put it at the end of a single cart updating function, if such a beast exists?

Also, do you have any feedback on cha0s's version of the patch?

Anonymous’s picture

i didn't see such a beast, but it would make sense if for it to exist from an API point of view.

can't say i have time to work on it right now, but i'd review a patch that introduced it.

rszrama’s picture

Ok, so I had to reroll this. As I did it I noticed that all the places we're manually rebuilding the cache are after a call to uc_cart_add_item() (for obvious reasons). What isn't obvious is why we don't simply change uc_cart_add_item() to rebuild the cache if it does indeed add an item to the cart. Wouldn't that get around having to sprinkle the calls to clear the cache in all the other modules? Can you think of any adverse affects?

(Attaching the rerolled version of the prior patch.)

Island Usurper’s picture

We shouldn't do this because uc_cart_add_item() is used inside a loop in cart links, uc_cart_login_update(), and uc_product_kit_add_to_cart(). When I mentioned this to Ryan, he brought up adding "yet another" parameter to uc_cart_add_item() to control whether it rebuilds the cart cache or not. I think that could work. I would default the $rebuild parameter to TRUE since I think we use it that way more often.

rszrama’s picture

Ok, re-rolled this based on my suggestion and Lyle's concurrence.

Island Usurper’s picture

Doesn't seem to break anything. I'm not really set up to test how it performs, though.

Anonymous’s picture

ok, i'll look test this shortly. i'm not sure if this will help the recursive calls, but this looks like an ok approach.

Anonymous’s picture

Status: Needs review » Reviewed & tested by the community

backported this to our production code, and it works well. this is RTBC as far as i'm concerned.

rszrama’s picture

Status: Reviewed & tested by the community » Fixed

Huttah!

Status: Fixed » Closed (fixed)
Issue tags: -Release blocker, -ubercamp sprint

Automatically closed -- issue fixed for 2 weeks with no activity.