-
Notifications
You must be signed in to change notification settings - Fork 83
Description
Description
A clean environment is required for checks to run smoothly. There are a few possible scenarios that can be followed to run checks cleanly without affecting the site. So that users can run it on any site environment like production or staging.
The approach should be not to generate test content to the primary database tables, and all modifications to the site DB should be made through test DB tables. The plugin should create test DB tables with a different prefix specially generated through the plugin to populate test data for the site. Using wpdb::set_prefix, the plugin can change the base prefix of the site test DB tables. This approach can be run on the production site as well because the plugin is generating tables for demo content on need in the test tables.
Also, this approach will only be used for runtime checks that require DB operations to run. Runtime checks should only be run if the plugin is already active on the site. The plugin can prompt the user to activate the plugin when the check is initiated.
The plugin can use its own object-cache.php drop-in file added into the wp-content directory which overrides the DB table prefix. It can be used to run early and pause plugins other than the one being tested. It should not actually implement an object cache. If the site is already using its own object-cache.php file, the file should be renamed and conditionally required by the plugin checker’s object-cache.php file (see below note on an additional consideration there).
This approach will need to add to the database directly and preparations will need to do clean-ups to the database content. For example, some checks would require demo content to be added to the test DB tables via preparations.
Note: If a site is using a persistent object cache, it should be paused for the check requests as well so that it doesn’t add any of the demo test data into the real object cache of the site. The plugin can bypass it using the object-cache.php file.
Acceptance Criteria
- A
Runtime_Environment_Setupclass exists inincludes/Checker- The
Runtime_Environment_Setupclass will be responsible for setting up the WordPress environment to run Runtime checks. - A public
setup()method exists in the class and will handle the following steps:- Creates the demo database tables (if they do not already exist)
- The demo tables will use a new
wppc_prefix. - The demo tables will be populated with the required installation data by running the regular WP installation functions.
- The demo tables will use a new
- Add the object-cache.php drop-in file to the wp-content folder. If an object-cache.php file already exists, this step is skipped.
- Creates the demo database tables (if they do not already exist)
- A public
cleanup()method exists in the class to reverse the changes from thesetup()method- Delete the demo database tables.
- Remove the plugin checker object-cache.php file.
- The
- A
Plugin_Request_Utilityclass exists inincludes\Utilities- A public static
initialize_runner()method exists in the class that will handle the following steps.- Instantiate both runner classes
- Call both runner classes
is_plugin_check()methods. - If the
is_plugin_methodcall returns true, the runnersprepare()method is called. - If any check requested is a
Runtime_Check, theprepare()method will update the wpdb prefix with wpdb::set_prefix to match the demo tables prefix.
- A public static
get_runner()method exists.- This method returns the runner instance that is being used for the current request, or
nullif neither is being relevant (e.g. when it is not a plugin checker request).
- This method returns the runner instance that is being used for the current request, or
- A public static
- Include an
object-cache.phpdrop-in file.- The object-cache.php drop-in file will call the
Plugin_Request_Utility::initialize_runner()method.
- The object-cache.php drop-in file will call the
References
Below are issues/PR's from the Performance Lab plugin related to the object-cache.php drop in.
- object-cache.php conflicts with third party plugins performance#612
- Enhance object-cache.php drop-in interoperability with other plugins performance#616
- Introduce Server-Timing API as part of infrastructure performance#551
- Implement Server-Timing API foundation as well as basic load time metrics performance#553