Hi!

I have edited the default groups directory view and made it a table view. I have added the OG: Group: Post Count which shows the node counts within the group.
Problem: Public nodes are counted twice.

Thanks

Comments

roald’s picture

Did some more research:

Apparently the number of nodes for each group comes from this query (dev_ is my table prefixes):
SELECT COUNT(*)
FROM dev_node n
INNER JOIN dev_og_ancestry oga ON n.nid = oga.nid
INNER JOIN dev_node_access na ON na.nid = n.nid
WHERE (na.grant_view >= 1
AND ((na.gid = 0 AND na.realm = 'all') OR (na.gid = 0 AND na.realm = 'og_public') OR (na.gid = 51 AND na.realm = 'og_subscriber') OR (na.gid = 42 AND na.realm = 'og_subscriber')))
AND ( n.status = 1 AND oga.group_nid = 51 )

Looking at the rows returned by SELECT * from the same query shows me that each node is returned twice, one with realm = og_public and one with realm = og_subscriber, which in fact doubles the counted number of rows for public nodes.

Changing the query into the following seems to do the trick:
SELECT COUNT(distinct n.nid)
FROM dev_node n
INNER JOIN dev_og_ancestry oga ON n.nid = oga.nid
INNER JOIN dev_node_access na ON na.nid = n.nid
WHERE (na.grant_view >= 1
AND ((na.gid = 0 AND na.realm = 'all') OR (na.gid = 0 AND na.realm = 'og_public') OR (na.gid = 51 AND na.realm = 'og_subscriber') OR (na.gid = 42 AND na.realm = 'og_subscriber')))
AND ( n.status = 1 AND oga.group_nid = 51 )

Honestly I'm not 100% sure it is the OG-module that builds this query, but at least DEVEL refers to og_handler_post_count

Hoping this is sufficiant to fix the issue

Thanks

roald’s picture

Believe it or not, seems that I was able to fix the issue myself:

og_views.inc line 1198:

Exchanged
$cnt = db_result(db_query(db_rewrite_sql("SELECT COUNT(*) FROM {node} n INNER JOIN {og_ancestry} oga ON n.nid = oga.nid WHERE n.status = 1 AND oga.group_nid = %d $where"), $data->nid, $fielddata['options'] ));

with
$cnt = db_result(db_query(db_rewrite_sql("SELECT COUNT(n.nid) FROM {node} n INNER JOIN {og_ancestry} oga ON n.nid = oga.nid WHERE n.status = 1 AND oga.group_nid = %d $where"), $data->nid, $fielddata['options'] ));

Maybe someone can review my work and implement the changes if it seems correct :-)

Thanks

roald’s picture

Category: support » bug

Changed category to bug-report

moshe weitzman’s picture

Status: Active » Fixed

committed. thanks.

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.