Re-instate background indexing via WP Cron#20005
Re-instate background indexing via WP Cron#20005thijsoo merged 35 commits intofeature/cron-background-indexationfrom
Conversation
The previous background indexing hook had "\" characters in its handle. This may cause issues with automations that use bash (in combination with WP-CLI) for instance, which sees that as a escaping character.
thijsoo
left a comment
There was a problem hiding this comment.
CR 🚧 Did not do the ACC yet. Might be nice to run a quick code coverage report on the unit tests you touched because a couple of methods in those files are not covered yet and I think that is a quick win to add those :)
| @@ -127,9 +168,7 @@ protected function set_up() { | |||
| public function test_get_conditionals() { | |||
| static::assertEquals( | |||
There was a problem hiding this comment.
I am confused why this is suddenly a static?
There was a problem hiding this comment.
This PR just adds an additional test following the pattern of the existing ones. I'm not sure if it's rightfully a static, but maybe it's out of the scope to investigate this here?
| Indexing_Helper::class, | ||
| $this->getPropertyValue( $this->instance, 'indexing_helper' ) | ||
| ); | ||
| static::assertInstanceOf( |
There was a problem hiding this comment.
Same as above? Maybe check the entire file.
| */ | ||
| public function test_register_hooks() { | ||
| Monkey\Actions\expectAdded( 'admin_init' ); | ||
| Monkey\Actions\expectAdded( 'wpseo_indexable_index_batch' ); |
There was a problem hiding this comment.
Normally I think we always use has( instead of expectAdded, not sure if there is a reason you chose to use this except that there was already a use here.
There was a problem hiding this comment.
It's something that I moved from the original PR, but I think it is because we already have been using expectAdded here, so for uniformity reasons?
…ts for the background checking
Context
Summary
This PR can be summarized in the following changelog entry:
wp yoast indexWP CLI command on a staging siteRelevant technical choices:
register_shutdown_function. See the old PR for details around that: https://github.com/Yoast/wordpress-seo/pull/18050/filesTest instructions
Test instructions for the acceptance test before the PR gets merged
This PR can be acceptance tested by following these steps:
For all tests:
Note:
When
selected pagesis mentioned in the instructions, we mean:Dashboard->HomepageDashboard->UpdatespagePlugins->Installed pluginspageSettings->PermalinkspageFor the main feature:
wp cron event delete "wpseo_indexable_index_batch"wp post generate --count=100 --post_author=adminwith WP CLI). Once the posts are created, add some internal links in them. A couple of them should have at least some content (for testing prominent words, when Premium is enabled, in the second run of the tests)selected pages.wp cron event listand confirm that you see thewpseo_indexable_index_batchscheduled action there, that's to run in 1 hour.wp cron event run "wpseo_indexable_index_batch".wp cron event listand confirm that you see thewpseo_indexable_index_batchscheduled action there again, that's to run in 15mins now.add_filter( 'Yoast\WP\SEO\enable_cron_indexing', '__return_false' );Error: Invalid cron event 'wpseo_indexable_index_batch'selected pageson your site.wp cron event run "wpseo_indexable_index_batch"and checking the database until you get a different response:Error: Invalid cron event 'wpseo_indexable_index_batch'define( 'DISABLE_WP_CRON', true );.DELETE FROM wp_options WHERE option_name LIKE ('%\_transient\_%');selected pages.For re-enabling the cron but only upon admin page load, not on frontend load:
wp cron event run "wpseo_indexable_index_batch"until you getError: Invalid cron event 'wpseo_indexable_index_batch'. This means that indexables are all created and the cron is now unscheduledwp cron event listand confirm that thewpseo_indexable_index_batchis NOT in that listwp cron event listand confirm that thewpseo_indexable_index_batchis NOT in that list (this means that we're not performing heavy queries on the frontend)selected pagesand again runwp cron event listbut now confirm that thewpseo_indexable_index_batchIS in that listwp cron event run "wpseo_indexable_index_batch"until you getError: Invalid cron event 'wpseo_indexable_index_batch'and repeat this test with Premium enabled and confirm the same - Note that the cron indexation will finish but the SEO optimization button will still be enabled because prominent words are not able to be indexed via background indexingadd_filter( 'Yoast\WP\SEO\enable_cron_indexing', '__return_false' );added. This time thewpseo_indexable_index_batchwill never be created and there's no need to check the last step (the one that begins with runningwp cron event run "wpseo_indexable_index_batch")For re-enabling the cron indexing when indexable versions are increased:
wp cron event run "wpseo_indexable_index_batch"until you getError: Invalid cron event 'wpseo_indexable_index_batch'. This means that indexables are all created and the cron is now unscheduledwp cron event listand confirm that thewpseo_indexable_index_batchis NOT in that listIndexable_Builder_Versionsclass (in the src\values\indexables\indexable-builder-versions.php file) increase the version of post indexables in theindexable_builder_versions_by_type, aka.'post' => 3,selected pages, runwp cron event listand confirm that thewpseo_indexable_index_batchIS in that list.wp cron event run "wpseo_indexable_index_batch"until you getError: Invalid cron event 'wpseo_indexable_index_batch'.postas theirobject_typehave3as theirversionFor further checking that heavy queries will NEVER run in the frontend:
wp cron event delete "wpseo_indexable_index_batch"and delete transients:DELETE FROM wp_options WHERE option_name LIKE ('%\_transient\_%');Yoast\WP\SEO\Actions\Indexing\Abstract_Indexing_Actioncaller.For the staging sites rule of not indexing there:
define( 'WP_ENVIRONMENT_TYPE', 'staging' );to your wp-config.php (or remove theyoast_seo_development_modeif you're on Local WP)wp yoast index.wp cron event run wpseo_indexable_index_batchproduction. Refresh one of theselected pages.wp cron event run wpseo_indexable_index_batchwp yoast indexwp cron event run wpseo_indexable_index_batch, confirm that you gotExecuted the cron event 'wpseo_indexable_index_batch'response but also confirm that no new indexables were created in the db.DISABLE_WP_CRONis set totrue) and add this filter (so that we set a really large number for the shutdown indexing, so we make sure it is supposed to run on every page load):selected pagesand the check the db to confirm that there were no indexables created.Relevant test scenarios
Test instructions for QA when the code is in the RC
QA can test this PR by following these steps:
For testing the actual cron indexation without WP CLI:
add_filter( 'Yoast\WP\SEO\enable_cron_indexing', '__return_false' );wp post generate --count=45 --post_author=adminwith WP CLI). Once the posts are created, add a couple of internal links in them.selected pages.Impact check
This PR affects the following parts of the plugin, which may require extra testing:
Also:
DISABLE_WP_CRONis set totrue. If that is not the case, the site should be indexed gradually; 15 posts every 15 minutes (granted the site gets visitors every 15 minutes).define( 'DISABLE_WP_CRON', true );add this filter (so that we set a really large number for the shutdown indexing, so we make sure it is supposed to run on every page load):define( 'DISABLE_WP_CRON', true );and confirm that the background indexation never run (aka no indexables were created when visiting the Dashboard->Home, Plugins->Install plugins, Yoast's settings pages. But make sure you check that in under 15mins, because the cron indexation might create the indexables and mess up with our tests)wpseo_shutdown_indexation_limitfilter above and regression test this PR.UI changes
Other environments
[shopify-seo], added test instructions for Shopify and attached theShopifylabel to this PR.Documentation
Quality assurance
Innovation
innovationlabel and noted the work hours.Fixes #