diff --git a/core/modules/migrate_drupal/config/migrate.migration.d6_search_settings.yml b/core/modules/migrate_drupal/config/migrate.migration.d6_search_settings.yml index 7ea5c20..348658f 100644 --- a/core/modules/migrate_drupal/config/migrate.migration.d6_search_settings.yml +++ b/core/modules/migrate_drupal/config/migrate.migration.d6_search_settings.yml @@ -4,13 +4,11 @@ source: variables: - minimum_word_size - overlap_cjk - - search_cron_limit - search_tag_weights - search_and_or_limit process: 'index:minimum_word_size': minimum_word_size 'index:overlap_cjk': overlap_cjk - 'index:cron_limit': search_cron_limit destination: plugin: d8_config config_name: search.settings diff --git a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateSearchConfigsTest.php b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateSearchConfigsTest.php index 414296f..c71930a 100644 --- a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateSearchConfigsTest.php +++ b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateSearchConfigsTest.php @@ -41,6 +41,5 @@ public function testSearchSettings() { $config = \Drupal::config('search.settings'); $this->assertIdentical($config->get('index.minimum_word_size'), 3); $this->assertIdentical($config->get('index.overlap_cjk'), TRUE); - $this->assertIdentical($config->get('index.cron_limit'), 100); } } diff --git a/core/modules/node/config/schema/node.schema.yml b/core/modules/node/config/schema/node.schema.yml index 506049b..7aa1aa6 100644 --- a/core/modules/node/config/schema/node.schema.yml +++ b/core/modules/node/config/schema/node.schema.yml @@ -87,3 +87,6 @@ search.plugin.node_search: sequence: - type: integer label: 'Influence' + cron_limit: + type: integer + label: 'Number of items to index per cron run' diff --git a/core/modules/node/config/search.page.node_search.yml b/core/modules/node/config/search.page.node_search.yml index 597f4e3..92ef4e1 100644 --- a/core/modules/node/config/search.page.node_search.yml +++ b/core/modules/node/config/search.page.node_search.yml @@ -8,3 +8,4 @@ weight: -10 plugin: node_search configuration: rankings: { } + cron_limit: 100 diff --git a/core/modules/node/lib/Drupal/node/Plugin/Search/NodeSearch.php b/core/modules/node/lib/Drupal/node/Plugin/Search/NodeSearch.php index fb0538a..4d95a26 100644 --- a/core/modules/node/lib/Drupal/node/Plugin/Search/NodeSearch.php +++ b/core/modules/node/lib/Drupal/node/Plugin/Search/NodeSearch.php @@ -7,6 +7,7 @@ namespace Drupal\node\Plugin\Search; +use Drupal\Component\Utility\MapArray; use Drupal\Core\Config\Config; use Drupal\Core\Database\Connection; use Drupal\Core\Database\Query\SelectExtender; @@ -291,7 +292,7 @@ protected function addNodeRankings(SelectExtender $query) { * {@inheritdoc} */ public function updateIndex() { - $limit = (int) $this->searchSettings->get('index.cron_limit'); + $limit = $this->configuration['cron_limit']; $result = $this->database->queryRange("SELECT DISTINCT n.nid, d.reindex FROM {node} n LEFT JOIN {search_dataset} d ON d.type = :type AND d.sid = n.nid WHERE d.sid IS NULL OR d.reindex <> 0 ORDER BY d.reindex ASC, n.nid ASC", 0, $limit, array(':type' => $this->getPluginId()), array('target' => 'slave')); $nids = $result->fetchCol(); @@ -540,6 +541,7 @@ protected function getRankings() { public function defaultConfiguration() { $configuration = array( 'rankings' => array(), + 'cron_limit' => 100, ); return $configuration; } @@ -548,6 +550,20 @@ public function defaultConfiguration() { * {@inheritdoc} */ public function buildConfigurationForm(array $form, array &$form_state) { + + // Indexing throttle: + $form['indexing_throttle'] = array( + '#type' => 'details', + '#title' => $this->t('Indexing throttle') + ); + $form['indexing_throttle']['cron_limit'] = array( + '#type' => 'select', + '#title' => $this->t('Number of items to index per cron run'), + '#default_value' => $this->configuration['cron_limit'], + '#options' => MapArray::copyValuesToKeys(array(10, 20, 50, 100, 200, 500)), + '#description' => $this->t('The maximum number of items indexed by this search page in each pass of a cron maintenance task. If necessary, reduce the number of items to prevent timeouts and memory errors while indexing.', array('@cron' => url('admin/reports/status'))), + ); + // Output form for defining rank factor weights. $form['content_ranking'] = array( '#type' => 'details', @@ -583,6 +599,7 @@ public function submitConfigurationForm(array &$form, array &$form_state) { unset($this->configuration['rankings'][$var]); } } + $this->configuration['cron_limit'] = $form_state['values']['cron_limit']; } } diff --git a/core/modules/search/config/schema/search.schema.yml b/core/modules/search/config/schema/search.schema.yml index 68e6877..e1ef850 100644 --- a/core/modules/search/config/schema/search.schema.yml +++ b/core/modules/search/config/schema/search.schema.yml @@ -14,9 +14,6 @@ search.settings: type: mapping label: 'Indexing settings' mapping: - cron_limit: - type: integer - label: 'Number of items to index per cron run' overlap_cjk: type: boolean label: 'Simple CJK handling' diff --git a/core/modules/search/config/search.settings.yml b/core/modules/search/config/search.settings.yml index 09c09cb..1e73038 100644 --- a/core/modules/search/config/search.settings.yml +++ b/core/modules/search/config/search.settings.yml @@ -1,7 +1,6 @@ and_or_limit: 7 default_page: node_search index: - cron_limit: 100 overlap_cjk: true minimum_word_size: 3 tag_weights: diff --git a/core/modules/search/lib/Drupal/search/Plugin/SearchIndexingInterface.php b/core/modules/search/lib/Drupal/search/Plugin/SearchIndexingInterface.php index 26edef5..0b137d4 100644 --- a/core/modules/search/lib/Drupal/search/Plugin/SearchIndexingInterface.php +++ b/core/modules/search/lib/Drupal/search/Plugin/SearchIndexingInterface.php @@ -34,10 +34,10 @@ * When implementing this method, your module should index content items that * were modified or added since the last run. PHP has a time limit * for cron, though, so it is advisable to limit how many items you index - * per run using config('search.settings')->get('index.cron_limit'). Also, - * since the cron run could time out and abort in the middle of your run, you - * should update any needed internal bookkeeping on when items have last - * been indexed as you go rather than waiting to the end of indexing. + * per run (see the cron_limit setting on NodeSearch). Also, since the cron + * run could time out and abort in the middle of your run, you should update + * any needed internal bookkeeping on when items have last been indexed as you + * go rather than waiting to the end of indexing. */ public function updateIndex(); diff --git a/core/modules/search/lib/Drupal/search/SearchPageListController.php b/core/modules/search/lib/Drupal/search/SearchPageListController.php index 6f86728..e835c01 100644 --- a/core/modules/search/lib/Drupal/search/SearchPageListController.php +++ b/core/modules/search/lib/Drupal/search/SearchPageListController.php @@ -7,7 +7,6 @@ namespace Drupal\search; -use Drupal\Component\Utility\MapArray; use Drupal\Core\Config\ConfigFactory; use Drupal\Core\Config\Entity\DraggableListController; use Drupal\Core\Entity\EntityInterface; @@ -169,20 +168,6 @@ public function buildForm(array $form, array &$form_state) { '#submit' => array(array($this, 'searchAdminReindexSubmit')), ); - $items = MapArray::copyValuesToKeys(array(10, 20, 50, 100, 200, 500)); - - // Indexing throttle: - $form['indexing_throttle'] = array( - '#type' => 'details', - '#title' => $this->t('Indexing throttle') - ); - $form['indexing_throttle']['cron_limit'] = array( - '#type' => 'select', - '#title' => $this->t('Number of items to index per cron run'), - '#default_value' => $search_settings->get('index.cron_limit'), - '#options' => $items, - '#description' => $this->t('The maximum number of items indexed in each pass of a cron maintenance task. If necessary, reduce the number of items to prevent timeouts and memory errors while indexing.', array('@cron' => url('admin/reports/status'))), - ); // Indexing settings: $form['indexing_settings'] = array( '#type' => 'details', @@ -300,9 +285,6 @@ public function submitForm(array &$form, array &$form_state) { search_reindex(); } - $search_settings - ->set('index.cron_limit', $form_state['values']['cron_limit']) - ->save(); drupal_set_message($this->t('The configuration options have been saved.')); } diff --git a/core/modules/search/lib/Drupal/search/Tests/SearchConfigSettingsFormTest.php b/core/modules/search/lib/Drupal/search/Tests/SearchConfigSettingsFormTest.php index 0cff49d..8fe78fb 100644 --- a/core/modules/search/lib/Drupal/search/Tests/SearchConfigSettingsFormTest.php +++ b/core/modules/search/lib/Drupal/search/Tests/SearchConfigSettingsFormTest.php @@ -303,6 +303,33 @@ public function testMultipleSearchPages() { } /** + * Test that changing the throttle value is reflected in the config. + */ + function testNodeSearchSettingsForm() { + // This doesn't test the indexing itself, since the form only goes down to + // indexing 10 nodes per batch, and creating and indexing at least 11 nodes + // would be a slow test for the benefit gained. The throttle itself is + // tested by SearchMultilingualEntityTest::testIndexingThrottle(). + + $indexing_throttle = \Drupal::config('search.page.node_search')->get('configuration.cron_limit'); + $this->assertEqual($indexing_throttle, 100, 'Default indexing throttle is 100.'); + + $this->drupalGet('admin/config/search/settings/manage/node_search'); + $this->assertText(t('Number of items to index per cron run')); + + $edit = array( + 'cron_limit' => 50, + ); + $this->drupalPostForm('admin/config/search/settings/manage/node_search', $edit, t('Save search page')); + $this->assertText(t('The Content search page has been updated.')); + + $indexing_throttle = \Drupal::config('search.page.node_search')->get('configuration.cron_limit'); + $this->assertEqual($indexing_throttle, 50, 'Indexing throttle is now 50.'); + + // Content ranking settings are tested by SearchRankingTest + } + + /** * Checks that the search page operations match expectations. * * @param string $id diff --git a/core/modules/search/lib/Drupal/search/Tests/SearchMultilingualEntityTest.php b/core/modules/search/lib/Drupal/search/Tests/SearchMultilingualEntityTest.php index 282b7ab..a9c1d95 100644 --- a/core/modules/search/lib/Drupal/search/Tests/SearchMultilingualEntityTest.php +++ b/core/modules/search/lib/Drupal/search/Tests/SearchMultilingualEntityTest.php @@ -98,10 +98,12 @@ function setUp() { * Tests for indexing throttle with nodes in multiple languages. */ function testIndexingThrottle() { + $plugin = $this->container->get('plugin.manager.search')->createInstance('node_search'); // Index only 4 items per cron run. - \Drupal::config('search.settings')->set('index.cron_limit', 4)->save(); + $configuration = $plugin->getConfiguration(); + $configuration['cron_limit'] = 4; + $plugin->setConfiguration($configuration); // Update the index. This does the initial processing. - $plugin = $this->container->get('plugin.manager.search')->createInstance('node_search'); $plugin->updateIndex(); // Run the shutdown function. Testing is a unique case where indexing // and searching has to happen in the same request, so running the shutdown