There are a few places where DB writes are being performed during plugin initialization or when performing normal frontend requests to the site:
https://github.com/ampproject/amp-wp/blob/f1af0aba711f25cd93ad9efb903764adeab54d4f/amp.php#L404-L420
(Removed class-amp-story-templates.php instance since code removed in #4315.)
(Removed AMP_Theme_Support::check_for_cache_misses() example since removed in #4178.)
These can potentially cause race conditions where concurrent requests both cause an update to be done at the same time. It's also not great for performance to have DB writes being performed in response to frontend requests.
I suggest that each of these cases be refactored with wp_schedule_single_event() which can then be used to perform the writes during WP Cron, and thus avoid the race condition.
It's true that scheduling a WP Cron event is itself a DB write, but at least this a more proper way to do it. Otherwise, there could be a repeating task every X minutes to see if the above tasks need to be performed.
该提问来源于开源项目:ampproject/amp-wp