Woocommerce generates more sessions than users
This is my first WooCommerce installation, so maybe I don't understand what's going on, but what I see from Google Analytics is the site I put live last Friday, there were ~ 7500 sessions for yesterday, but the session count ( from _wp_session_expriry% query) there will probably be about 50,000 sessions in the wp_options table generated in the last 12 hours since I wiped all sessions. I destroyed the sessions because from the table this table has no indexes and yet WooCommerce hits it with a ton of session data, but then the killer was the usual WooCommerce temporary data deletion. It turned out that each of these deletes takes over a minute with 300,000 sessions in the table because the queries contain LIKEs.
So far I have checked that the robots are not going crazy and have been rummaging through the Apache logs, and although I have some IP addresses with a very high hit rate, I donβt understand why I would be getting new sessions for WooCommerce, but not Google Analytics. Apache logs show actual page images as per Google Analytics page count, so I suspect WooCommerce or plugins for this problem.
So now I have reduced the problem by indexing wp_orders and reducing the session expiration time to 2 hours, but that doesn't explain why I have this insane number of sessions in the first place.
I'm using the most recent of all: WP 3.9, WC 2.1.7+ plus some other WC plugins, one of which joins the WC (WooCommerce Currency Switcher) session, but it looks like it just connects to the session control.
So I have one big question, and then a more architectural one:
Biggest: Can anyone suggest why I am getting so many sessions in wp_options versus GA users (in order of magnitude)? And I'm much more confident.
And then: Is there a clean way to move WC sessions into a separate table? wp_options doesn't seem like an obvious choice, considering how everyone else uses it for a lot of CRUD actions that need to be responsive, I would expect to see the woocommerce_sessions table.
source to share
Solution to clean up sessions in
Woocommerce > System Status > Tools, Clear all sessions
And also change your Robots.txt to exclude bots from running Woo-Cart :) The search engine bots go through all the add to cart buttons causing it to create a bunch of extra cart sessions.
Change your robots.txt; add this:
User-agent: *
Disallow: /*add-to-cart=*
I want woocommerce to automatically clean up this mess!
source to share
We had this problem, the database was 1.3 GB! When this is so large, the above method of using "clear all sessions" suffocates. You need to run a query in mySQL (multiple times until they are cleaned up):
DELETE FROM wp_options
WHERE option_name LIKE '_wc_session_%' OR option_name LIKE '_wc_session_expires_%'
LIMIT 500
Or a plugin like this one might help: http://shop.webaware.com.au/downloads/delete-expired-transients/
source to share