wp-media / imagify-plugin

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

cache imagify user response even in case of error #916

Closed MathieuLamiot closed 1 week ago

MathieuLamiot commented 2 weeks ago

Description

Fixes the increase of requests to the Imagify API after release of 2.2.3 image

Users might be impacted as the fetching of information about their subscription from the API will now be delayed by 5 minutes in case of error on the first try. As a result, some data might not be available for 5 minutes initially if there was an issue when fetching the user data. It will be automatically retried after 5 minutes.

Type of change

Detailed scenario

If you don't have a valid API key for instance, Imagify plugin currently tries to fetch user data on each admin page opening. After this fix, the call should happen only once every 5 minutes.

Technical description

Documentation

We now store the result of get_imagify_user even in case of error, so that this result can be reused next time it is needed without doing again a call to the API.

New dependencies

List any new dependencies that are required for this change.

Risks

If a user fixes the issue, some part of the admin dashboard might take 5 minutes to get updated. For instance, after setting up the API key, the account information might not be available immediately.

Mandatory Checklist

Code validation

Code style

Additional Checks

MathieuLamiot commented 1 week ago

After testing a bit, the only impact I could see is when someone enters a wrong API key, navigates a bit the admin, then enters a valid key. After this, it takes a few minutes for the admin bar to display the license and quota. I would need someone to validate that this reduced the number of API calls, maybe by adding a log and comparing before/after the fix.

MathieuLamiot commented 1 week ago

@wordpressfan confirmed it should be working to reduce 401: https://wp-media.slack.com/archives/CU0F6EGQ1/p1731051235420369?thread_ts=1730995819.928759&cid=CU0F6EGQ1

I played a bit with the version and it seems working on my end.

Mai-Saad commented 1 week ago

@wordpressfan Thanks for the PR.

Note: initial test plan is here as per requirements from discussions https://wpmediaqa.testrail.io/index.php?/runs/view/927&group_by=cases:section_id&group_order=asc