One of the things I was working on were making the forums more "forum-like" in light of InvisionBoard or PHPbb. These patches include the forum_user() hook on load to include the total post counts (nodes + comments) .
An example of the patch in action is available here. The theme is a modified chamleon theme, but the data is just to the left of the user posts.
The patch creates $user->post_count in which can be used from anywhere instead of just in viewing a users profile. This patch also contains mysql and postgres Indexes and a tuned SQL query that has low server load. I feel this is a very useful feature for drupal as other modules can be created such as post_roles (X post for certain roles or other status'). The forum hook module can be expanded to show the post count, or leave it to a community module. One thing I did add was the ablility to enable/disable post_counting. If this is needed, please let me know and it will be added.
Showing index usage in MySQL
mysql> explain select count(distinct n.nid)+count(distinct c.cid) as post_count FROM users as u INNER JOIN node as n ON n.uid=u.uid INNER JOIN comments as c ON c.uid=u.uid WHERE u.uid=1\G
*************************** 1. row ***************************
table: u
type: const
possible_keys: PRIMARY
key: PRIMARY
key_len: 4
ref: const
rows: 1
Extra: Using index
*************************** 2. row ***************************
table: n
type: ref
possible_keys: uid,node_count
key: node_count
key_len: 4
ref: const
rows: 8
Extra: Using where; Using index
*************************** 3. row ***************************
table: c
type: ref
possible_keys: post_count
key: post_count
key_len: 4
ref: const
rows: 10
Extra: Using where; Using index
3 rows in set (0.00 sec)
Query in action
mysql> select count(distinct n.nid)+count(distinct c.cid) as post_count FROM users as u INNER JOIN node as n ON n.uid=u.uid INNER JOIN comments as c ON c.uid=u.uid WHERE u.uid=1;
+------------+
| post_count |
+------------+
| 81 |
+------------+
1 row in set (0.00 sec)
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | database.mysql_3.patch | 619 bytes | crackerjackmack |
| #2 | database.pgsql_1.patch | 617 bytes | crackerjackmack |
| #1 | database.mysql_2.patch | 811 bytes | crackerjackmack |
| forum.module_2.patch | 745 bytes | crackerjackmack |
Comments
Comment #1
crackerjackmack commentedmysql patch
Comment #2
crackerjackmack commentedpostgres patch
Comment #3
crackerjackmack commentedoops, there was a bug in the first one....this one is right
Comment #4
killes@www.drop.org commentedThere is no reason that this hook has to be in forum.module. Could also be in the proposed community.module.
a remark: If you want to add info to the user object you need to make sure that user_load is executed. it is usually not for performace reasons.
Comment #5
kae commentedthis sounds great. I wish we could use it on drupal.org