Skip to:
Content
Pages
Categories
Search
Top
Bottom

Bug or not?? bp_get_forum_topic_count causing massive memory requirements and timeouts

  • @3sixty

    Participant

    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) so I’m not keen to use this function on page that’s going to be pulled thousands of times per day.

    So now I’m wondering why this function even exists?? The weird thing is that bp_forum_pagination_count() performs a similar function directly below the All Topics tab (“Viewing topic 1 to 20 (23,466 total topics)”) and that function is instantaneous; no waiting. This function works by calling another function to generate the total topic count: bp_core_number_format( $forum_template->total_topic_count )

    Pretty sure this should be filed as a bug but wanted to see if anyone else had thoughts on this? 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?

Viewing 5 replies - 1 through 5 (of 5 total)
  • @r-a-y

    Keymaster

    bp_forum_pagination_count() uses the $forum_template global, which is why it outputs instanteously.

    bp_get_forum_topic_count() calls bp_forums_total_topic_count(), which has a do_action( ‘bbpress_init’ ) line. Try commenting out this line in /bp-forums.php and see if the memory problems persist.

    If it the memory problems persist, then it’s a problem with the BB_Query instance, which I have no idea how to debug!

    @3sixty

    Participant

    Right, as I noted, you already get total_topic_count “for free” with $forum_template.

    “Try commenting out this line in /bp-forums.php and see if the memory problems persist.”
    Sorry to be unclear – yes, exactly – that’s how I found the problem.

    I did backtrack through the code, and I think you are right – it is a problem with the BB_Query instance. I would strongly advise against using bp_get_forum_topic_count unless this is addressed!!

    Reported on trac: https://trac.buddypress.org/ticket/2421

    @r-a-y

    Keymaster

    @3sixty – So you tried commenting out the do_action line for the bp_forums_total_topic_count() function? And it didn’t do anything?
    http://pastebin.com/rqGPKxrD

    You can try replacing the bp_forums_total_topic_count() function in /bp-forums.php with this:
    http://pastebin.com/qvpy4CS2

    See if the memory problems occur with my mod.

    @djpaul

    Keymaster

    For those following at home, do_action( ‘bbpress_init’ ) is the code that loads all the bbPress classes and access into memory.

    @3sixty

    Participant

    No no, the opposite – I’m good. Works now.

    Maybe I’m not understanding you, though – what I did is comment out the call to bp_get_forum_topic_count() in the bp-template. I think you’re saying I should stop that function from registering in the first place by commenting out the related do_action. That’s probably a cleaner approach.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Bug or not?? bp_get_forum_topic_count causing massive memory requirements and timeouts’ is closed to new replies.
Skip to toolbar