wp-media / imagify-plugin

Speed up your website with lighter images without losing quality.
https://imagify.io
73 stars 26 forks source link

Cache user API call for 5 minutes #907

Closed remyperona closed 1 month ago

remyperona commented 1 month ago

Description

Cache the user API call for 5 minutes to avoid the request on each page load.

Type of change

Detailed scenario

Technical description

Documentation

Following changes made in #899, #900, #902, the User class is used on more pages than before, and this class makes an API call to get the user information, with a timeout of 10 seconds.

Caching the result of the API call allows to prevent the request on every page.

It was not possible to use the existing imagify_get_cached_user() function, because this function returns a cache that doesn't match the result from the API call, but a result from the cache of the User class itself.

Mandatory Checklist

Code validation

Code style

wordpressfan commented 1 month ago

@Tabrisrp Do u know what is the difference between this PR and the code found here: https://github.com/wp-media/imagify-plugin/blob/5684433e2a7d126b312de47ed05d21022483374c/inc/functions/admin.php#L391-L424

Now we inroduce a transient called imagify_user_cache and there is another one called imagify_user

if it's OK to introduce this transient, should we update the data being saved to have those attributes?

https://github.com/wp-media/imagify-plugin/blob/5684433e2a7d126b312de47ed05d21022483374c/inc/functions/admin.php#L414-L415

remyperona commented 1 month ago

I explained it in the technical description, they're not exactly the same data. One is caching the API call itself, the other is caching the User class.

Ideally we would implement things differently, but it would require too much work right now.

Mai-Saad commented 1 month ago

On PR => refresh admin won't send API call to imagify till this transient is expired imagify_check_api_version On trunk => API call is there with every refresh