this may be somewhat of a noob question as I just started administering an ExpressionEngine site that uses CartThrob. My client complained of the site being slow during the shopping / checkout process so I enabled SQL profiling in EE to look into it.

I noticed something strange, which is that CartThrob is making many queries during each page load, far more than I would expect. Basically the page template uses


six times to show six different products. Then uses


within each one to pull some various information about the product. The strange thing is that a single SQL SELECT and another SQL UPDATE query seem to be running over and over again on the same page (each of them runs over 50 times on one page load).

SELECT `cart`
FROM (`exp_cartthrob_cart`)
WHERE `id` = '12345'

UPDATE `exp_cartthrob_cart`
SET `cart` = 'a-bunch-of-encoded-gibberish',
    `timestamp` = 1386624719,
    `url` = 'http://example.com/product-details'
WHERE `id` = '12345';

Why would cartthrob be running these same queries over and over again, and how can I optimize this code to prevent it?

  • I've noticed that same pair of queries running many times on one of our sites too. Did anyone figure out a way to stop CartThrob from doing those queries so many times? Commented Dec 1, 2016 at 21:58

1 Answer 1


Sounds like a poorly coded template... First, you should aim to refactor it using the multi_add_to_cart_form instead of the simple add_to_cart_form:


This will give you a single form for all 6 products so should reduce CT's load by 6X. You should then look into other optimisations and caching strategies for further gains (in particular, try to minimise or eliminate usage of EE's embed tag). It's likely that if the previous developer missed the multi_add_to_cart_form they probably missed a lot of other things...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.