Skip to:

Opened 14 years ago

Closed 14 years ago

Last modified 14 years ago

#2421 closed defect (bug) (fixed)

bp_get_forum_topic_count causing massive memory requirements and timeouts

Reported by: 3sixty's profile 3sixty Owned by:
Milestone: 1.5 Priority: normal
Severity: Version:
Component: Core Keywords:


As reported here:

I previously reported that the BuddyPress /forums page (“Group Forums Directory”) was crashing due to memory limit errors on a BP Forum that had 20,000+ topics. I kept bumping it up until I finally got the page to render at a memory limit of 200M. The problem is the function bp_get_forum_topic_count is causing massive memory requirements and timeouts. This function that displays the total number of topics in the tab: “All Topics (23,466)” Even with the memory limit high enough, bp_get_forum_topic_count takes a good 4 seconds to generate that number (on a VPS that otherwise pulls up pages in a fraction of a second).

I’m wondering why this function even exists, and if it needs to exist, can it be fixed?? r-a-y suspects (and I agree) that this is probably an issue with the BB_Query instance.

bp_forum_pagination_count() already performs a similar function directly below the All Topics tab (“Viewing topic 1 to 20 (23,466 total topics)”) and all it does is call $forum_template->total_topic_count - very simple

Given that total_topic_count is already stored in the $forum_template, is bp_get_forum_topic_count a dog that serves no purpose and causes massive memory issues to boot?

Change History (5)

#1 @r-a-y
14 years ago

As reported in the forum thread, commenting out the do_action('bbpress_init') line in the bp_forums_total_topic_count() function fixes this:

The alternative is to rewrite the function to the following:

function bp_forums_total_topic_count() {
        $query = new BP_Forums_Template_Forum;
        $count = $query->total_topic_count;
        return $count;

#2 @DJPaul
14 years ago

Since this ticket was created 7 months ago, [3369] has happened which has prevented bbPress potentially load itself twice. I have looked through the main bbPress query class and can see no workarounds to significantly improve any further memory use; hopefully, new bbPress plugin will be more memory-friendly when we integrate that into BuddyPress.

I'm going to try creating manylots of forum topics to look at memory use but I think this will be a wontfix for now.

#3 @DJPaul
14 years ago

I was so wrong. Even though this particular function is only used in one place in BP-Default, direct SQL was/is so much faster than using a BBPress query. Tested on a 10k topic group. Forum directory still very slow to load.

#4 @djpaul
14 years ago

  • Resolution set to fixed
  • Status changed from new to closed

(In [3659]) Improve speed of forums' total topic count by alot. Fixes #2421

#5 @djpaul
14 years ago

(In [3660]) Speed up forum directory's "last active" bbPress SQL query to stop it fetching information we aren't using. Helps fix #2421

Note: See TracTickets for help on using tickets.