Not sure if I'm posting in the correct section so please move if needed...
I have a site with a large number of orders and the also_purchased module is slowing the site down. When looking at the stats, the also_purchased sql query is constantly at the top of the charts causing high memory and cpu usage.
The orders table has over 160k rows and orders_products has more than 2.7mil rows so the original query is obviously our bottleneck. I'm pretty sure this doesn't become so obvious on smaller stores, but I see potential for improvement (for everyone) and would be submitting a PR when done.
I'm considering two options (both would involve a new database table). The module would then pull data from this table instead of doing self-joins on this huge table. I'm wondering which of the 2 would be better:
#1 - creating a cron job that would update the new table daily
#2 - using an observer on checkout_success to populate the new table
Obviously both have downsides.
If it's a cron job, it's not user-friendly because one needs to set it up. I guess it could be tied in to the frontend and triggered by the first visitor of the day, but is that really the way to go? It could also be tied to the admin and rely on admin logging in, but what if the admin doesn't login for awhile, are we happy with "obsolete" data? On the other hand, if the admin doesn't login for days, it's obviously not a very busy store and this isn't really a critical feature to be up-to-date.
If using an observer on checkout_success, we're essentially slowing down the checkout process and are risking database locks at the most critical step. I know it's not a huge query and it shouldn't cause issues, but still - it's at a critical moment.
I'm thinking the observer is the obvious way to go, but would like to hear some thoughts and ideas before going for it...


Reply With Quote

