Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
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()
Comment | File | Size | Author |
---|---|---|---|
#2 | unnecessary_queries-1674344.patch | 3.02 KB | mototribe |
Comments
Comment #1
BerdirYes, makes sense, patches welcome :)
Comment #2
mototribe CreditAttribution: mototribe commentedyeah, it's about time for me to learn how to create a patch ;-)
Please let me know if I did it correctly.
Thanks!
Comment #3
BerdirPath looks ok visually, remember to set the issue status to needs review so that the testbot picks up the patch.
Comment #4
BerdirThanks, commited.
Comment #5.0
(not verified) CreditAttribution: commentedtypos