Download & Extend

Comment count not correct when node_privacy_byrole is installed

Project:Live Discussion
Version:4.6.x-1.x-dev
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:closed (won't fix)

Issue Summary

When node_privacy_byrole is installed, the comment count for a non-admin user is greater than the real comment count.

There is a select in the live_discussions module:

      $query = "SELECT c.nid, n.title, COUNT(c.nid) AS comment_count, MAX(c.timestamp) AS the_time FROM {comments} c ".
               "LEFT JOIN {node} n ON n.nid = c.nid ".$select_blog." WHERE c.status = 0 GROUP BY c.nid ORDER BY the_time DESC ".
               "LIMIT ".$commented_limit;

It should be changed to this:

      $query = "SELECT c.nid, n.title, COUNT(DISTINCT c.cid) AS comment_count, MAX(c.timestamp) AS the_time FROM {comments} c ".
               "LEFT JOIN {node} n ON n.nid = c.nid ".$select_blog." WHERE c.status = 0 GROUP BY c.nid ORDER BY the_time DESC ".
               "LIMIT ".$commented_limit;

Notice that in the third column we should select cid instead of nid and because node_privacy_byrole will duplicate the rows, we must also use DISTINCT inside the COUNT.

Comments

#1

Status:active» closed (won't fix)

I don't want to modify the module for a single contrib module, but I've added your issue and solution to the readme file.

#2

Is there any reason why you consider the original SELECT to be better than the modified one?

I mean even if we ignore the issue raised by the module when node_privacy_byrole is insatlled, still it's odd that you count node ID's insted of comment ID's.

I have tested this on my drupal site, and I have not found any secondary effects because of the change.