Issue #2715113 by anshuljain2k8, SwapS, dagmar, Fabianx, ndobromirov: Watchdog logging of all searches is performance hit; need ability to turn it off (7.x)

merge-requests/26/head
Fabian Franz 2016-11-29 10:16:31 -08:00
parent 7a94baeb94
commit dc0064dd91
4 changed files with 29 additions and 4 deletions

View File

@ -125,6 +125,16 @@ function search_admin_settings($form) {
'#options' => $module_options,
'#description' => t('Choose which search module is the default.')
);
$form['logging'] = array(
'#type' => 'fieldset',
'#title' => t('Logging')
);
$form['logging']['search_logging'] = array(
'#type' => 'checkbox',
'#title' => t('Log searches'),
'#default_value' => variable_get('search_logging', 1),
'#description' => t('If checked, all searches will be logged. Uncheck to skip logging. Logging may affect performance.'),
);
$form['#validate'][] = 'search_admin_settings_validate';
$form['#submit'][] = 'search_admin_settings_submit';

View File

@ -12,6 +12,7 @@ function search_uninstall() {
variable_del('minimum_word_size');
variable_del('overlap_cjk');
variable_del('search_cron_limit');
variable_del('search_logging');
}
/**

View File

@ -57,9 +57,10 @@ function search_view($module = NULL, $keys = '') {
}
// Only search if there are keywords or non-empty conditions.
if ($keys || !empty($conditions)) {
// Log the search keys.
watchdog('search', 'Searched %type for %keys.', array('%keys' => $keys, '%type' => $info['title']), WATCHDOG_NOTICE, l(t('results'), 'search/' . $info['path'] . '/' . $keys));
if (variable_get('search_logging', TRUE)) {
// Log the search keys.
watchdog('search', 'Searched %type for %keys.', array('%keys' => $keys, '%type' => $info['title']), WATCHDOG_NOTICE, l(t('results'), 'search/' . $info['path'] . '/' . $keys));
}
// Collect the search results.
$results = search_data($keys, $info['module'], $conditions);
}

View File

@ -1453,7 +1453,7 @@ class SearchConfigSettingsForm extends DrupalWebTestCase {
parent::setUp('search', 'search_extra_type');
// Login as a user that can create and search content.
$this->search_user = $this->drupalCreateUser(array('search content', 'administer search', 'administer nodes', 'bypass node access', 'access user profiles', 'administer users', 'administer blocks'));
$this->search_user = $this->drupalCreateUser(array('search content', 'administer search', 'administer nodes', 'bypass node access', 'access user profiles', 'administer users', 'administer blocks', 'access site reports'));
$this->drupalLogin($this->search_user);
// Add a single piece of content and index it.
@ -1502,6 +1502,19 @@ class SearchConfigSettingsForm extends DrupalWebTestCase {
);
$this->drupalPost('admin/config/search/settings', $edit, t('Save configuration'));
$this->assertNoText(t('The configuration options have been saved.'), 'Form does not save with an invalid word length.');
// Test logging setting. It should be on by default.
$text = $this->randomName(5);
$this->drupalPost('search/node', array('keys' => $text), t('Search'));
$this->drupalGet('admin/reports/dblog');
$this->assertLink('Searched Content for ' . $text . '.', 0, 'Search was logged');
// Turn off logging.
variable_set('search_logging', FALSE);
$text = $this->randomName(5);
$this->drupalPost('search/node', array('keys' => $text), t('Search'));
$this->drupalGet('admin/reports/dblog');
$this->assertNoLink('Searched Content for ' . $text . '.', 'Search was not logged');
}
/**