budgetneon / v2pagecache

Page Cache for OpenCart V2.X
58 stars 26 forks source link

pagecache handling of cart is broken #4

Closed budgetneon closed 8 years ago

budgetneon commented 8 years ago

When open cart moved from 2.0.x to 2.1.x, they got rid of the 'cart' session variable. This is what we were using to tell if the session had items in the cart, and therefore neither cache the request, nor serve a cached page for the request.

It looks like the only way to tell if there's items in the cart now is to query the database. That's too heavy of an operation to do with a pagecache, so I'm going to have to think about how to deal with this.

Until this is fixed, the pagecache is not going to be usable in production.

COBS12 commented 8 years ago

I'm eager to have this issue solved, tried it out in my store - amazing results! Until i tried add-to-cart :)

Hoping for a quick fix soon, thank you :)

BrettyWhite commented 8 years ago

I enjoyed using this as well. I see it as having one of 2 possibilities and of the second, I am unaware of its difficulty. We could either give in and make a query on each page load, with the thought that a single query is still much faster than many queries or 2, add back in a cart session variable manually to re-create what was in previous versions.

COBS12 commented 8 years ago

I must say that this - unfortunately - is way beyond my skills :) I an quite a newbie within the Opencart world, and have just begun working woth SEO. My site became lightning fast with this extension.. Its really a shame that it does not work anymore :(

@brettywill Could you please explain what you mean by creating a query on each page load? I am in the learning process of this world :)

Thank you.

BrettyWhite commented 8 years ago

Querying the database to see if there are any items in the cart. If there is no session variable for the cart, the only way to know if that user had items in the cart would be to check the database. This check would have to be done before each page is loaded because if there was an item in the cart, you would not load a cached page nor would you cache that page.

I know @budgetneon wants to avoid this at all costs because it is still a heavier operation than just checking the session cart variable.

I am a PHP developer but haven't done much customization with opencart. I need to stop being lazy and make myself a development instance of it to help out more. I will play around and reply with anything I find that may be of use.

Thanks

COBS12 commented 8 years ago

Thank you very much for the detailed explanation :)

I went from zero knowledge, to modifying my own CSS-files, adding a favicon, and so on.

I have (maybe had?) plans of lauching my store to the public, in one months time, but honestly i must say that I do not have the skills to make my site faster without this extension :(

My load time is roughly 7 seconds (!!!), and I have even crushed all of my images to a decent size.. Don't know whats happening, but I can only hope that someone with the right knowledge and skills, can find a solution.

budgetneon commented 8 years ago

Brett has the issue exactly right.

I can fix this, but I'm choosing between 3 approaches.

a) Patch the opencart core with ocmod to restore the cart session variable as items are added or removed from the cart. This creates no extra queries, but I've never been a fan of ocmod or vqmod. Patching core files with live applied diffs feels clunky.

b) Patch the opencart core with override engine. Cleaner than 'a)' above, but now I have to make it prerequisite for the page cache, explain to people that it has to be installed first, etc.

c) Add a database query to every non-cached page load, separately. This will slow down non-cached page loads slightly. I hate to do this, but on the other hand, opencart does already make LOTS of queries per page load already. One more may not be a significant difference.

I suppose 'c)' probably makes the most sense, but I hate it.

P.S, Cobs12...on this:

My load time is roughly 7 seconds (!!!)

Do you have a lot of categories? See this: http://forum.opencart.com/viewtopic.php?f=121&t=131313 ... scroll down and someone updated it for opencart 2.x.

budgetneon commented 8 years ago

Edit: May have spoke too soon...it is a good solution, but only usable with Opencart 2.2.x. The event system in 2.0.x and 2.1.x doesn't have hooks for the cart, and is completely different in function. Sigh.

I think I've found a better solution.

Opencart has a lesser known way to interact with core functionality called 'Events / Script Notifications'.

There appears to be three events I can hook to that might catch all cases of the cart being modified (add/edit/delete products).

controller/checkout/cart/remove/after controller/checkout/cart/add/after controller/checkout/cart/after

That would allow me to synchronize a cart session variable, and would only add work/queries when the cart was being interacted with, versus every page load.

It may be a while still though, as there's not really much documentation on events, and I don't know if those 3 events cover all the bases.

COBS12 commented 8 years ago

Thank you very much for the information on the categories issue :)

Your new solution sounds like the right way to go. Is there anything we can do to help you in this process? I don't own developing skills, but anything else that might help you out - you name it :)

Looking forward to having this amazing extension

COBS12 commented 8 years ago
COBS12 commented 8 years ago

Oh.. Sorry - didn't notice your edit... :(

budgetneon commented 8 years ago

Fixed. I put in the simpler solution of checking the cart contents on every uncached page load.

Also...

You can download from here, or on the opencart extension page: http://www.opencart.com/index.php?route=extension/extension/info&extension_id=19079

budgetneon commented 8 years ago

Would appreciate it if you tested and let me know if it seems to be working correctly.

BrettyWhite commented 8 years ago

Thanks, I will test

COBS12 commented 8 years ago

@budgetneon You are the man!!!

Thank you SO much for fixing this so fast! I will begin testing right now :)

BrettyWhite commented 8 years ago

Initial impressions look to be very good. I appreciate all of your work. I will keep an eye on it and report back any findings :)

ag462391 commented 8 years ago

http://www.opencart.com/index.php?route=extension/extension/info&extension_id=19079 It works? Link does not work. Where can I download and try?