I’d like to create a list of recent comments, specific to each user on my network (Buddypress).
My best idea so far is pretty lame: DB Query on all user’s blogs, compare dates, select top 10 by date. To me, it sounds a too heavy load for the the server.
Any alternative and better ideas? 🙂
Thanks!
There’s a different posts and comments table per site, so not really.
That said, you can and should keep track of blog ids they’ve commented on in a user meta to speed things up in the first round, and cache the formatted result in a separate usermeta to speed things up in subsequent rounds. These are easy enough to be tracked and invalidate on save/delete post/comment.
The activity feed shows comments from any blogs from all persons registered in the buddypress site (pulldown menu show recent comments) so why not duplicate it, sort it and dump it in a widget on the screen?
If you’re using the blog tracking feature of BuddyPress, rather than querying WordPress’ comments tables, I suggest you query the activity stream for ‘new_blog_comment’ updates only. The activity stream already records and aggregates this information into one database table.
Something like:
if ( bp_has_activities( 'user_id=1&object=blog&action=new_blog_comment' ) )
See also http://codex.buddypress.org/developer-docs/custom-buddypress-loops/the-activity-stream-loop/