summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDries Buytaert2009-05-25 15:43:38 (GMT)
committerDries Buytaert2009-05-25 15:43:38 (GMT)
commit982c7c3cc841e6ccb85f41e7526a7de428ab91e0 (patch)
tree682cf912634aab056244163d1205cd75598db9f2
parentf0940b1dbf630c438bf99fb21dd62518cebfd81a (diff)
- Patch #250729 by andypost, catch, R.Muilwijk et al: remove some unnecessary queries and search index.
-rw-r--r--modules/comment/comment.module21
-rw-r--r--modules/search/search.test13
2 files changed, 26 insertions, 8 deletions
diff --git a/modules/comment/comment.module b/modules/comment/comment.module
index 8506434..8ea8e91 100644
--- a/modules/comment/comment.module
+++ b/modules/comment/comment.module
@@ -710,12 +710,14 @@ function comment_node_delete($node) {
*/
function comment_node_update_index($node) {
$text = '';
- $comments = db_query('SELECT subject, comment, format FROM {comment} WHERE nid = :nid AND status = :status', array(
- ':nid' => $node->nid,
- ':status' => COMMENT_PUBLISHED
- ));
- foreach ($comments as $comment) {
- $text .= '<h2>' . check_plain($comment->subject) . '</h2>' . check_markup($comment->comment, $comment->format, '', FALSE);
+ if ($node->comment != COMMENT_NODE_HIDDEN) {
+ $comments = db_query('SELECT subject, comment, format FROM {comment} WHERE nid = :nid AND status = :status', array(
+ ':nid' => $node->nid,
+ ':status' => COMMENT_PUBLISHED
+ ));
+ foreach ($comments as $comment) {
+ $text .= '<h2>' . check_plain($comment->subject) . '</h2>' . check_markup($comment->comment, $comment->format, '', FALSE);
+ }
}
return $text;
}
@@ -732,8 +734,11 @@ function comment_update_index() {
* Implementation of hook_node_search_result().
*/
function comment_node_search_result($node) {
- $comments = db_query('SELECT comment_count FROM {node_comment_statistics} WHERE nid = :nid', array('nid' => $node->nid))->fetchField();
- return format_plural($comments, '1 comment', '@count comments');
+ if ($node->comment != COMMENT_NODE_HIDDEN) {
+ $comments = db_query('SELECT comment_count FROM {node_comment_statistics} WHERE nid = :nid', array('nid' => $node->nid))->fetchField();
+ return format_plural($comments, '1 comment', '@count comments');
+ }
+ return '';
}
/**
diff --git a/modules/search/search.test b/modules/search/search.test
index b7f5e9c..fc85653 100644
--- a/modules/search/search.test
+++ b/modules/search/search.test
@@ -503,5 +503,18 @@ class SearchCommentTestCase extends DrupalWebTestCase {
$this->assertText($comment_body, t('Comment body text found in search results.'));
$this->assertNoRaw(t('n/a'), t('HTML in comment body is not hidden.'));
$this->assertNoRaw(check_plain($edit_comment['comment']), t('HTML in comment body is not escaped.'));
+
+ // Hide comments.
+ $this->drupalLogin($this->admin_user);
+ $node->comment = 0;
+ node_save($node);
+
+ // Invoke search index update.
+ $this->drupalLogout();
+ $this->drupalGet($GLOBALS['base_url'] . '/cron.php', array('external' => TRUE, 'query' => 'cron_key=' . variable_get('cron_key', 'drupal')));
+
+ // Search for $title.
+ $this->drupalPost('', $edit, t('Search'));
+ $this->assertNoText($comment_body, t('Comment body text not found in search results.'));
}
}