Minor performance issue. In comment.module (4.7 and 5.0) the function comment_link makes some unnecessary queries in cases where there are no comments. That is, there's no need to run comment_num_new if comment_num_all establishes that there aren't any comments on a node. (These two functions build the familiar "4 comments - 2 new comments" type links in teaser views.)
The problem is that comment_num_new in turn calls node_last_viewed, and then runs its own query to see if any of the node's comments are more recent than the user's last visit to the node.
if (user_access('access comments')) {
$all = comment_num_all($node->nid);
$new = comment_num_new($node->nid);
But if there aren't any comments, why bother checking to see if there are any _new_ comments?
if (user_access('access comments')) {
$all = comment_num_all($node->nid);
if ($all) {
$new = comment_num_new($node->nid);
}
Trivial, but annoying to know that on a teaser page with 10 nodes, no comments, and links turned on, 20 extra db queries are being made...
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | comment_remove_extra_query_47.patch.txt | 1 KB | heine |
| #4 | comment_link_remove_extraneous_query.patch.txt | 952 bytes | heine |
| #1 | comment_40.patch | 330 bytes | chromeyellow |
Comments
Comment #1
chromeyellow commentedOookay... then here's a patch incite interest. Simply puts the call to comment_num_new in a conditional statement; comment_num_new is only called if comment_num_all establishes that there are any comments.
Comment #2
chromeyellow commentedThe above patch is against 4.7.4; not sure if 'feature requests' are still being received so I've (presumptuously?) recategorized as a task.
5.x version forthcoming.
Comment #3
chromeyellow commentedThe above patch is against 4.7.4; not sure if 'feature requests' are still being received so I've (presumptuously?) recategorized as a task.
5.x version forthcoming.
Comment #4
heine commentedA bug IMO.
Comment #5
dries commentedCommitted to CVS HEAD. Thanks.
Comment #6
heine commentedComment #7
heine commentedPatch is different than the one in #1 and against 4.7.x-dev.
Thanks chromeyellow!
Comment #8
killes@www.drop.org commentedapplied
Comment #9
chromeyellow commentedHeine, thanks for handling the 5.x version and the tweaked 4.7; Dries and Killes, thanks for the commits!
Comment #10
(not verified) commented