strangerstudios / sitewide-sales

Run Black Friday, Cyber Monday, or other flash sales on your WordPress-powered eCommerce or membership site with WooCommerce, Easy Digital Downloads, and Paid Memberships Pro.
https://sitewidesales.com
GNU General Public License v3.0
3 stars 6 forks source link

Optimization: cache queries and values for certain callback methods #152

Open kimcoleman opened 1 year ago

kimcoleman commented 1 year ago

Is your feature request related to a problem? Please describe. To keep this plugin as optimized as possible, it would be useful to do a run through and cache some queries/methods.

We should update the call back methods in the modules to cache queries.

For example, https://github.com/strangerstudios/sitewide-sales/blob/dev/modules/ecommerce/pmpro/class-swsales-module-pmpro.php#L855-L892

From Jason: This could also be a good opportunity to go through the process with our dev team as the need comes up a fair bit.. There are a few different methods to caching (static vars, WP cache functions, transients), and each has its place.

Static vars best for cases where there is a single value that doesn't change throughout the course of the page load (may be the case here). Easiest, don't really need to invalidate the cache later.

WP get/set cache functions to potentially cache between page loads, or if you need to save values for different parameters (we sometimes still save in static vars and create a cache hash/key), and when invalidating/breaking the cache later is not complicated.

Transients are best for fully generated HTML snippets, should be saved between page loads, and is easy or at least possible to invalidate... or it's not so bad for it to be out of date.

Kim Coleman 1 hour ago I’ll log the caching in the callback notes here as an issue.

ideadude commented 1 year ago

In addition to some we need to cache, you can use the Query Monitor plugin and check the "duplicate queries" report to find queries that should be cached in SWS. Should browse around the admin and frontend pages and check the report for seeing queries in different contexts.

Screenshot 2023-11-01 at 5 43 59 PM