Forum Moderators: open

Message Too Old, No Replies

Clicking add to cart takes forever with mysql

         

ecommerceprofit

10:41 pm on Nov 5, 2006 (gmt 0)

10+ Year Member Top Contributors Of The Month



Why does clicking on my "add to bag" button take 3 - 5 seconds to "add to cart" The request takes too long because other sites are immediate in getting items added to a cart. The cart code is written in php and uses mysql. Someone mentioned something about indexing?

txbakers

2:39 am on Nov 6, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Your database query could be faulty. To add a record to the database doesn't require an index, only reading from the database. But the problem could be in the reading (display) rather than the posting to (insert).

Perhaps you can post your code (just the query parts) and someone can take a look.

ecommerceprofit

4:33 pm on Nov 6, 2006 (gmt 0)

10+ Year Member Top Contributors Of The Month



Unfortunately I'm between programmers right now so am unable to post code :( Thanks for your help - I remember the last guy who fixed it mentioned indexing - I'll mention both solutions to the next programmer.

physics

4:54 pm on Nov 6, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I doubt this is anything specific to php/mysql as opposed to other languages/databases. Generally php/mysql is pretty fast. Probably bad coding/db design or slow server (are you on a shared server with high load?).

ecommerceprofit

5:55 pm on Nov 6, 2006 (gmt 0)

10+ Year Member Top Contributors Of The Month



Have a dedicated server at a reputable web hosting company - think it's bad coding as you mention.

jtara

5:35 am on Nov 7, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Indexing problem makes sense. It would be unusual to have an "add to cart" that doesn't subsequently display what you have in the cart. :)

If the code does a fresh query to get the cart content after adding, then the lack of an index on, say, the customer ID (or customer ID + item ID), would certainly slow things down if you have a lot of customers, as it would have to do an exhaustive search through the database.

Has it gotten progressively worse? Are reports on customers or orders slow as well?

If this is the issue, hate to tell you, but this is Database 101. Get a more experienced programmer next time.

ecommerceprofit

6:05 am on Nov 7, 2006 (gmt 0)

10+ Year Member Top Contributors Of The Month



Yep - it seems like the add to cart part is a bit slower over several months :-) Your answer is exactly what I needed to hear - I am trying to convince my managed hosting provider to fix for me but they do not like to get into code, etc. - I need a new programmer asap - working on this now - your diagnosis should help so thanks!

ecommerceprofit

5:13 pm on Nov 7, 2006 (gmt 0)

10+ Year Member Top Contributors Of The Month



It's super fast now! The tech at my hosting provider fixed it - indexing made the database lightning fast - add to cart was super duper quick! Thanks for your help!

ecommerceprofit

5:35 am on Nov 8, 2006 (gmt 0)

10+ Year Member Top Contributors Of The Month



Now, I have a new problem that indexing created...because we want .html pages rather than dynamic pages, we run a script that generates these .html pages - the problem the indexing is causing makes it so when we add a new picture or add a new product (new html page in essence) they are not showing up. Any ideas?

jtara

6:04 am on Nov 8, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



the problem the indexing is causing makes it so when we add a new picture or add a new product (new html page in essence) they are not showing up.

There is no reason why indexing would cause this. Indexing is completely transparent to applications. (With the exception of applications that might interact in some way with the database schema - that is unlikely in this case.) Indexing just makes access faster when the database is accessed through an indexed key.

I do think you need to have a programmer look at this. It's clear that your old programmer was "experience challenged" :) Who knows what bizarre coding he might have done?

Indexing does take more time when adding database records. One possibility is that the addition of the record and the display of the record are being done in different processes, and the database wasn't locked during the add. So, the display code was run before the add was actually completed. This is also Database 101.

Are the new records simply not added (also not shown upon subsequent viewing), or just not displayed immediately after the add?

ecommerceprofit

10:47 pm on Nov 8, 2006 (gmt 0)

10+ Year Member Top Contributors Of The Month



Stay tuned...all kinds of little things are happening - it is the code obviously :( Luckily a programmer is helping me out a bit out of the kindness of his heart :-) Thanks again for caring about my problem - I owe you one!