pressable / pressable-cache-management

Pressable Cache Management Plugin
Other
2 stars 1 forks source link

Admin 5 second + ttfb lag time when plugin is active #1

Closed georgestephanis closed 2 years ago

georgestephanis commented 2 years ago

Esteban Cairol on the a8c side had duplicated the issue here:

https://thecarbonalmanac-issue-1172.mystagingwebsite.com/wp-admin/plugins.php

(this is a one off dev site, so if y'all want to check anything on it it's fine and shouldn't impact production)

When the plugin is deactivated the issue goes away -- for (our) reference the issue that we'd chased this down on was https://github.com/a8cteam51/team51-dev-requests/issues/1172

georgestephanis commented 2 years ago

I wonder if it's possible that part of the reason for this additional latency is that on every admin request:

https://github.com/pressable/pressable-cache-management-plugin/blob/a215f7c5fbd864fccea0b52ebfc1b703cdf5a215/pressable-cache-management.php#L60

if there's credentials in the database, it fires off API requests on page load:

https://github.com/pressable/pressable-cache-management-plugin/blob/a215f7c5fbd864fccea0b52ebfc1b703cdf5a215/admin/custom-functions/api_connection.php#L3-L26

with no caching or async?

So if the assorted API endpoints have any latency, those all stack onto every admin page's TTFB

https://my.pressable.com/auth/token https://my.pressable.com/v1/sites/ . $pressable_site_id

and -- as these requests in this case are hitting the Team51 affiliated site, it may take longer to respond than normal due to the hundreds of sites on our account? I don't know if that would impact the api response time however.

otarhe commented 2 years ago

Slack discussion: https://pressable.slack.com/archives/C2L9FBLSD/p1652297706496579

The TTFB issues has been resolved. I've updated the plugin on the test site so you can try it out: https://thecarbonalmanac-issue-1172.mystagingwebsite.com

The issue was caused by continues query to the API even when a request was not made.

I've updated the plugin to cache generated API access token and changed how request is made. The plugin is now faster compared to before and also the TTFB stacking onto every admin page's is now resolved.