Skip to:
Content

bbPress.org

Opened 14 years ago

Closed 13 years ago

Last modified 13 years ago

#1208 closed defect (bug) (wontfix)

No way to cache multiple options at once from a plugin

Reported by: nightgunner5's profile Nightgunner5 Owned by:
Milestone: 1.1 Priority: normal
Severity: normal Version:
Component: Back-end Keywords: has-patch needs-testing
Cc:

Description

Here's some bbPress Benchmark data from my local test forum:

 # 3 : 0.0003 seconds     function require, require_once, bb_cache_all_options
SELECT `meta_key`, `meta_value` FROM `bb_meta` WHERE `object_type` = 'bb_option' AND `meta_key` IN ('site_id','bb_db_version','name','description','uri_ssl','from_email','bb_auth_salt','bb_secure_auth_salt','bb_logged_in_salt','bb_nonce_salt','page_topics','edit_lock','bb_active_theme','active_plugins','mod_rewrite','datetime_format','date_format','avatars_show','avatars_default','avatars_rating','wp_table_prefix','user_bbdb_name','user_bbdb_user','user_bbdb_password','user_bbdb_host','user_bbdb_charset','user_bbdb_collate','custom_user_table','custom_user_meta_table','wp_siteurl','wp_home','cookiedomain','usercookie','passcookie','authcookie','cookiepath','sitecookiepath','secure_auth_cookie','logged_in_cookie','admin_cookie_path','core_plugins_cookie_path','user_plugins_cookie_path','wp_admin_cookie_path','wp_plugins_cookie_path','wordpress_mu_primary_blog_id','enable_xmlrpc','enable_pingback','throttle_time','bb_xmlrpc_allow_user_switching','bp_bbpress_cron','email_login','static_title','plugin_cookie_paths','wp_roles_map','gmt_offset','timezone_string');

 # 4 : 0.0002 seconds     function require, require_once, bb_get_option, bb_get_option_from_db
SELECT `meta_value` FROM `bb_meta` WHERE `object_type` = 'bb_option' AND `meta_key` = 'uri'

 # 5 : 0.0003 seconds     function require, require_once, require_once, bbPM->bbPM, bb_get_option, bb_get_option_from_db
SELECT `meta_value` FROM `bb_meta` WHERE `object_type` = 'bb_option' AND `meta_key` = 'bbpm_settings'

 # 6 : 0.0002 seconds     function require, require_once, require_once, bb_get_option, bb_get_option_from_db
SELECT `meta_value` FROM `bb_meta` WHERE `object_type` = 'bb_option' AND `meta_key` = 'akismet_key'

 # 7 : 0.0003 seconds     function require, require_once, require_once, php4bb_maybe_block, bb_get_option, bb_get_option_from_db
SELECT `meta_value` FROM `bb_meta` WHERE `object_type` = 'bb_option' AND `meta_key` = 'php4bb'

 # 8 : 0.0002 seconds     function require, require_once, do_action, call_user_func_array, role_manager_init_roles, bb_get_option, bb_get_option_from_db
SELECT `meta_value` FROM `bb_meta` WHERE `object_type` = 'bb_option' AND `meta_key` = 'role_manager_roles'

 # 9 : 0.0002 seconds     function require, require_once, do_action, call_user_func_array, role_manager_init_roles, bb_get_option, bb_get_option_from_db
SELECT `meta_value` FROM `bb_meta` WHERE `object_type` = 'bb_option' AND `meta_key` = 'role_manager_default'

The vast majority (55) of the options are grabbed from the database immediately in .0003 seconds and 1 query, and then 6 more are grabbed in .0014 seconds over a total of 6 queries.

I suggest that the first query should still happen as is, but after the plugins are loaded, a hook should allow plugins to add the option names that they need to a list, and all of the plugin options should be grabbed at once.

This wouldn't break old plugins because no changes would be made to existing functions.

Compatibility could be retained for older versions of bbPress by doing something like this:

function my_plugin_options_filter( $options ) {
	$options[] = 'my_example_option';

	return $options;
}

function my_plugin_options_action() {
	global $my_plugin_vars;

	$my_plugin_vars['example'] = bb_get_option( 'my_example_option' );
}

if ( function_exists( 'bb_cache_plugin_options' ) ) {
	add_filter( 'bb_cache_plugin_options', 'my_plugin_options_filter' );
	add_action( 'bb_plugin_options_cached', 'my_plugin_options_action' );
} else {
	my_plugin_options_action();
}

Attachments (1)

1208.diff (2.7 KB) - added by Nightgunner5 14 years ago.

Download all attachments as: .zip

Change History (8)

@Nightgunner5
14 years ago

#1 @GautamGupta
14 years ago

  • Keywords has-patch needs-testing added
  • Version changed from 1.0.1 to 1.0.2

#2 @kevinjohngallagher
14 years ago

  • Milestone changed from Future Release to 1.1

#3 @GautamGupta
14 years ago

  • Milestone changed from 1.1 to Future Release

I had a chat with Ben and he said we should move it forward for now.

#4 @mr_pelle
14 years ago

I think this ticket is pretty important; we also already have a candidate patch, so why delaying it?

P.S: Ben's patch has a typo @line 560: $keys should be $query_keys.

#5 @GautamGupta
14 years ago

You can check the chat here - https://irclogs.wordpress.org/chanlog.php?channel=bbpress&day=2010-07-25#m21829

I'm just concerned about the confusion, not about the patch. Maybe one could open up a ticket for the same thing in WordPress?

#6 @johnjamesjacoby
13 years ago

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

Since the bbPress plugin for WordPress allows us to use add_option to introduce new autoloaded options at no additional cost, closing this as wontfix.

#7 @johnjamesjacoby
13 years ago

  • Milestone changed from Future Release to 1.1
  • Version 1.0.2 deleted
Note: See TracTickets for help on using tickets.