Closed mslinnea closed 3 years ago
We fixed this performance issue by adding this to theme code:
remove_action( 'init', [ 'WPCOM_Legacy_Redirector', 'register_redirect_custom_capability' ] );
As for fixing this in the plugin, I think this should only run during plugin activation or during a plugin upgrade routine. It's important to make sure this only runs in a limited and controlled manner.
When plugins are activated by code on VIP, there is no plugin activation or upgrade routine.
But, we should be able to protect against by using the approach at https://docs.wpvip.com/how-tos/customize-user-roles/.
We experienced an issue with the customize-user-roles code suggestion. The issue is that when the version is changed, all page requests will attempt to update the option at the same time. On a site with a lot of traffic, this caused a brief site outage as the database experienced an overload. We moved this update option code to a CLI command so that it only runs once. Alternatively, it could be limited to running only in the admin, which most likely wouldn't create enough requests to overload the database.
@mslinnea Please see #94 - the hook is now admin_init
, the capability registration incorporates a version check, and we've added some unit tests to have more confidence that everything is working.
We noticed a performance issue with this plugin on VIP Go. The function register_redirect_custom_capability is hooked in to run at init, which calls wpcom_vip_add_role_caps on the VIP environment. This should only be called when the capabilities change, per the VIP documentation at https://wpvip.com/documentation/vip-go/custom-user-roles/