PHP Scripting Forums » bbpress plugins and modifications

[sticky]

Bugfix for bbpress notification plugin

(1 post)
  • Started 6 months ago by Olaf
Please support us by buying these products:

  1. After getting more and more users for this bbpress forum I got problems posting new topics/posts. While checking the bbpress forum I found this thread:

    http://bbpress.org/forums/topic/error-after-new-post-all-of-a-sudden

    The user here describes exactly the same problem. After some debugging I found the problems source: The plugin selects all user and tests than if a user has the topic in his favorites. Executing the plugin takes a lot of time after several thousands of registered users.

    I changed the function notification_select_all_users to:

    function notification_select_all_users($post_id) {
    	global $bbdb;
    	$all_users = $bbdb->get_results("
    		SELECT u.ID, u.user_email
    		FROM $bbdb->users AS u, $bbdb->usermeta AS um
    		WHERE u.ID = um.user_id
    		AND um.meta_key = 'favorites'
    		AND $post_id IN (um.meta_value)
    		AND u.user_status = 0");
    	return $all_users;
    }

    Next we need to change the function notification_new_post a little bit (also changed the coding style a little):

    function notification_new_post() {
    	global $bbdb, $bb_table_prefix, $topic_id, $bb_current_user;
    	$all_users = notification_select_all_users($topic_id); // add $topic_id
    	if (!empty($all_users)) { // test if user array is not empty
    		foreach ($all_users as $userdata) {
    			if ( notification_is_activated( $userdata->ID ) ) {
    				if ( is_user_favorite( $userdata->ID, $topic_id ) ) {
    					$topic = get_topic($topic_id);
    					$message = __("There is a new post on: %1\$s \nReply by: %2\$s \n\n%3\$s ");
    						mail( $userdata->user_email, bb_get_option('name') . ':' . __('Notification'),
    							sprintf( $message, $topic->topic_title, get_user_name($bb_current_user->ID), get_topic_link($topic_id) ),
    							'From: ' . bb_get_option('from_email')
    						);
    				}
    			}
    		}
    	}
    }

    This small modification will solve the problem and will produce a lower server load even for bbpress forum with only a few registered users.

    Posted 6 months ago #

RSS feed for this topic

Reply

You must log in to post.