Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Perfomance optimization - adding transients #89

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

photogenic89
Copy link
Contributor

@photogenic89 photogenic89 commented May 20, 2021

Following up on the conversation in issue #74 , I added transients to your plugin. It is now not necessary anymore to loop through all cart sessions but only to consult the value of this transient.

Once a product is added to the cart, the transient is set. It will be updated on any quantity changes. The transient is removed after the cart item expires or when the order is generated from the cart items.
Expiration time is calculated in seconds based on what users set up as an expiration time. If Expire Items is unchecked, expiration time is at 0, thus without any.

I did some basic testing, nothing extensive.

Possible issues:

  • You will find inside the method get_virtual_stock_available the WC method get_cart_item_quantities(). It can't be called in every scenario, I therefor added an !is_admin check. Not sure if this brings out faulty scenarios anywhere, it looked all fine on my end.
  • If expiration time is set to 0, the database might be filled with a lot of transients. In my case it's not important to me but other users might need a new option to flush the transients? Maybe when carts are manually cleared in the WooCommerce options?

Looking forward to hear your thoughts on this.

@photogenic89
Copy link
Contributor Author

Hej James,
have you had any time to look at this? It would be interesting for me to see what you think about the code.
Best
Jan

@jamesgol
Copy link
Owner

Sorry, other than a quick glance I have not had a chance yet. I'm hoping to have a chance sometime soon, but also build out some testing so the plugins functionality (and speed) can be compared.

@photogenic89
Copy link
Contributor Author

Sounds great! I'm not really sure how to test code speed myself, so your research would help a lot.

@photogenic89
Copy link
Contributor Author

Did you have a look at this pull request as well? If yes, was there any positive effect on speed? I can see you improved speed on your end with the newest version by unserializing session data only once.

@jamesgol
Copy link
Owner

Yes I did look over this and it's not the way I want to go with it, I only want to trust the WooCommerce count and don't want to be doing any additional math. I do have something like this mostly implemented but need to finish up a few things before I commit it. In my test with the added caching there was essentially no difference in speed between having 10 carts/sessions and having 15,000 (until it ran out of memory)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants