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...

Comments

chromeyellow’s picture

Priority: Minor » Normal
Status: Active » Needs review
StatusFileSize
new330 bytes

Oookay... 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.

chromeyellow’s picture

Category: feature » task

The 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.

chromeyellow’s picture

The 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.

heine’s picture

Category: task » bug
StatusFileSize
new952 bytes

A bug IMO.

dries’s picture

Status: Needs review » Fixed

Committed to CVS HEAD. Thanks.

heine’s picture

Version: 5.x-dev » 4.7.x-dev
Status: Fixed » Active
heine’s picture

Status: Active » Needs review
StatusFileSize
new1 KB

Patch is different than the one in #1 and against 4.7.x-dev.

Thanks chromeyellow!

killes@www.drop.org’s picture

Status: Needs review » Fixed

applied

chromeyellow’s picture

Heine, thanks for handling the 5.x version and the tweaked 4.7; Dries and Killes, thanks for the commits!

Anonymous’s picture

Status: Fixed » Closed (fixed)