I have node pages with 50 comments per node and noticed that I have tons of queries by privatemsg_is_disabled on that page.
I have all link options disabled since I'm only showing a privatemessage link on the profile using a views field.

When I remove "$url = privatemsg_get_link(user_load($comment->uid));" in privatemsg_comment_view() I don't get the extra queries.
How about moving it inside the "if" statement?

function privatemsg_comment_view($comment) {
  $types = array_filter(variable_get('privatemsg_link_node_types', array()));
  if (in_array(node_load($comment->nid)->type, $types) && variable_get('privatemsg_display_on_comments', 0)) {
    //moved inside if statement
    $url = privatemsg_get_link(user_load($comment->uid));
    if (!empty($url)){
		$links['privatemsg_link'] = array(
		  'title' => t('Send author a message'),
		  'href' => $url . '/' . t('Message regarding @comment', array('@comment' => trim($comment->subject))),
		  'query' => drupal_get_destination(),
		);
		$comment->content['links']['privatemsg'] = array(
		  '#theme' => 'links',
		  '#links' => $links,
		  '#attributes' => array('class' => array('privatemsg-send-link', 'privatemsg-send-link-node', 'links', 'inline')),
		);
	}
  }
}

ditto for privatemsg_node_view()

CommentFileSizeAuthor
#2 unnecessary_queries-1674344.patch3.02 KBmototribe
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Berdir’s picture

Yes, makes sense, patches welcome :)

mototribe’s picture

yeah, it's about time for me to learn how to create a patch ;-)

Please let me know if I did it correctly.

Thanks!

Berdir’s picture

Version: 7.x-1.2 » 7.x-1.x-dev
Status: Active » Needs review

Path looks ok visually, remember to set the issue status to needs review so that the testbot picks up the patch.

Berdir’s picture

Status: Needs review » Fixed

Thanks, commited.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Anonymous’s picture

Issue summary: View changes

typos