Skip to:

Opened 14 years ago

Closed 14 years ago

#2627 closed defect (bug) (fixed)

Excessive database connections caused by improper assignment of global var in bp_forums_load_bbpress()

Reported by: nickwondra's profile nickwondra Owned by:
Milestone: 1.2.6 Priority: normal
Severity: Version:
Component: Forums Keywords: has-patch


In the function bp_forums_load_bbpress() in the file bp-forums-bbpress.php, line 73 performs an improper reference assignment between two global variables:

$bb_roles =& $wp_roles;

Since $bb_roles and $wp_roles are globals in this function scope, they are already references so this assignment will not persist to the $bb_roles global object (it will only alter the value of $bb_roles in the scope of this function). The proper assignment should be as follows:

$bb_roles = $wp_roles;

This assignment persists the value of $bb_roles at the global scope to reference the same object as $wp_roles.

This improper assignment causes bp_forums_load_bbpress() to never assign a value to $bb_roles, so it runs in its entirety every time it is called even though it is only meant to run through once (see lines 9-10). Since bp_forums_load_bbpress() is called frequently (it is the target of the action 'bbpress_init') and it creates a new database connection through a new BBDB object, this can lead to a very high number of database connection attempts. Some hosts will refuse connections after a certain number of attempts in a given time limit. This can be a big problem, especially where the 'bbpress_init' action is called multiple times for a single user operation, such as adding a new topic -- it can result in things like the topic being created, but the user's initial post being lost.

I'm not up to speed on the current roadmap for upcoming milestones, so I'm leaving this as targeted at 1.3 (the default). Since this is such a simple fix, it would be great to get it into 1.2.6 if the schedule allows.


Attachments (1)

2627.001.patch (401 bytes) - added by r-a-y 14 years ago.
Patch based off nickwondra's suggestion

Download all attachments as: .zip

Change History (4)

14 years ago

Patch based off nickwondra's suggestion

#1 @r-a-y
14 years ago

  • Keywords has-patch added
  • Milestone changed from 1.3 to 1.2.6

Thanks for posting this, nickwondra.

Moving to 1.2.6 so it is seen.
A core dev will move it to 1.3 if deemed necessary.

#2 @johnjamesjacoby
14 years ago

Just tested this on a local and was able to duplicate.

The goal with passing it byref was so both globals would stay in alignment with each other, but by the time this code executes it shouldn't make a difference.

Committing in a sec.

#3 @johnjamesjacoby
14 years ago

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

(In [3258]) Fixes #2627 props nickwondra, r-a-y.

Note: See TracTickets for help on using tickets.