on every page, that is called on drupal when running bad behavior, there is code that checks to see if the bad behavior table exists.

I feel this should'nt be done h.ere and should only be done during the install, it is simply an unnessecary db call.

Cheers, Nick

Comments

NGRhodes’s picture

In the file bad-behavior-database.php line 12: if (defined("WP_BB_NO_CREATE")) ...

function wp_bb_db_create_tables() {
	global $wp_bb_db_failure;

	if (defined("WP_BB_NO_CREATE"))
		return;

	// Determine if we can skip all this
	// If this exists, table structure is presumed up to date
//	$query = "DESCRIBE `" . WP_BB_LOG . "` `denied_reason`;";
//	if (wp_bb_db_query($query) != 0) return;

	// Create everything
	$query = "CREATE TABLE IF NOT EXISTS `" . WP_BB_LOG . "` (
		`id` int(11) NOT NULL auto_increment,
		`ip` text NOT NULL,
		`date` datetime NOT NULL default '0000-00-00 00:00:00',
		`request_method` text NOT NULL,

Maybe if we could define this variable we could prevent this happening every time.

In the file bad-behavior-mediawiki.php there is this:

// Configuration
// To change the following settings, override them in MediaWiki's
// LocalSettings.php after including this file.

// In some configurations the automatic table creation may fail.
// You can create the table manually (see query in bad-behavior-database.php)
// and add this line to your LocalSettings.php:
//
//   define('WP_BB_NO_CREATE', true);

Putting

define('WP_BB_NO_CREATE', true);

in the function badbehavior_init() in badbehavior.module does stop the CREATE TABLE IF NOT EXISTS query being fired which is always a slow query on my server (above 5ms according to devel module).

Obviously for this to work we need to make sure the tables are created, which I guess could be done via an install file, which bypasses define('WP_BB_NO_CREATE', true);. This is beyond my understanding of drupal as I have only been looking at drupal code for a week.

I think this is a useful optimisation as it would save a few ms on every page presented to the end user.

dave reid’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.