Opened a thread for testing and have 87 posts in it. The "posts" column in the Forums list shows 175.
I'm guessing it is doubling the total (including original post) and rounding. Any idea why it would be doubling the count?

Comments

Michelle’s picture

Status: Active » Postponed (maintainer needs more info)

Sorry, I didn't mean to ignore this. If this is still a problem, please try disabling AF and let me know if the problem goes away.

Michelle

aharown07’s picture

Tks. Should get a chance to test this in a day or two.

Michelle’s picture

Status: Postponed (maintainer needs more info) » Closed (fixed)

No more info provided. Feel free to re-open if you can confirm it's due to AF.

Michelle

aharown07’s picture

Don't know what caused this, but it did prove to be temporary. At some point the post count returned to normal. If I see this again, I'll try to get more info before it goes away.

Michelle’s picture

Ok, thanks. Especially check if the problem is there if you turn AF off. That's usually the quickest way to rule out AF.

Michelle

Architeck’s picture

I can confirm this issue is caused by the AF module, although its not exactly doubling.

I have applied this patch http://drupal.org/node/284392#233 which has fixed the doubling of the topic count, but I am still having issues with the post count as described above.

When I modify this line, to show only topic count, then only comment count.

$forum->num_posts = $counts[$forum->tid]->topic_count + $counts[$forum->tid]->comment_count;

I can see that the topic count is fine, but the comment count is doubled for everyone except the root user 1

[EDIT]

After poking around with this a little more and comparing code with the core forum module, I was able to get the count results by changing the following code in the Advanced Forum module. [EDIT] Just realized that I had applied this patch to the core fourm.module to aswell.

So the steps to fix this issue would be as follows.

In core forum.module replace the following in the forum_get_forums funciton

  if (count($_forums)) {

    $counts = array();

    $sql = "SELECT r.tid, COUNT(n.nid) AS topic_count, SUM(l.comment_count) AS comment_count FROM {node} n INNER JOIN {node_comment_statistics} l ON n.nid = l.nid INNER JOIN {term_node} r ON n.vid = r.vid WHERE n.status = 1 GROUP BY r.tid";
    $sql = db_rewrite_sql($sql);
    $_counts = db_query($sql);
    while ($count = db_fetch_object($_counts)) {
      $counts[$count->tid] = $count;
    }
  }

In the advaced_forum.module replace the following in the forum_get_forums funciton

if (count($_forums)) {

    $counts = array();

    $sql = "SELECT r.tid, COUNT(n.nid) AS topic_count, SUM(l.comment_count) AS comment_count
            FROM {node} n
            INNER JOIN {node_comment_statistics} l ON n.nid = l.nid
            INNER JOIN {term_node} r ON n.vid = r.vid
            WHERE n.status = 1
            GROUP BY r.tid";
    $sql = db_rewrite_sql($sql);
    $_counts = db_query($sql);
    while ($count = db_fetch_object($_counts)) {
      $counts[$count->tid] = $count;
    }
  }

Replace both snippets from above with the following

if (count($_forums)) {

    $counts = array();

    $sql = "
      SELECT r.tid AS tid, n.nid AS nid, l.comment_count AS nid_comment_count
        FROM {node} n
        INNER JOIN {node_comment_statistics} l ON n.nid = l.nid
        INNER JOIN {term_node} r ON n.vid = r.vid
        WHERE n.status = 1
        GROUP BY r.tid, n.nid, l.comment_count";
    $sql_rewritten = db_rewrite_sql($sql);
    if ($sql_rewritten == $sql) {
      $sql = "
        SELECT r.tid, COUNT(n.nid) AS topic_count, SUM(l.comment_count) AS comment_count
          FROM {node} n
          INNER JOIN {node_comment_statistics} l ON n.nid = l.nid
          INNER JOIN {term_node} r ON n.vid = r.vid
          WHERE n.status = 1
          GROUP BY r.tid";
      $sql = db_rewrite_sql($sql);
    }
    else {
      $sql = "
        SELECT tid, COUNT(nid) AS topic_count, SUM(nid_comment_count) AS comment_count
          FROM ($sql_rewritten) AS forum_content_list
          GROUP BY tid";
    }
     $_counts = db_query($sql);
     while ($count = db_fetch_object($_counts)) {
       $counts[$count->tid] = $count;

    }
  }

My apologies in advance for the messy explanation, maybe someone can roll-up these changes into a patch file.

This applies to 6.x

salvis’s picture

@Architeck:

Rhetorical question: In what way does "your" solution differ from what JuliaKM proposed in #113611-43: Forum count incorrect when using access control modules?

You owe her a review, since you seem to confirm that her patch works...

[Since you're in the habit of editing your posts without leaving a comprehensible trail I'm stating here that at the time of this writing, your proposed solution is identical (including line-wrapping and spacing) to JuliaKM's patch. If the timestamp of your #6 should suddenly be later than my #7, then it will be obvious that you've doctored it.]

Architeck’s picture

@salvis

I am not claiming to have written the solution, the post I doctored above was to provide people who come across this issue with clear steps showing the process of how I was able to resolve the issue.

I thought I had clearly linked to the patch that I used, however it must have been lost with an edit. There are so many posts regarding this issue, its quite easy to loose track.

I have added a review comment to that thread to indicate the patch works. Sorry for the confusion.