From e2d3bb0acc08ec30bf166c0260903c2625a26727 Mon Sep 17 00:00:00 2001 From: saxmatt Date: Thu, 10 Jun 2004 08:42:25 +0000 Subject: [PATCH] Changes to options system and query improvements. git-svn-id: http://svn.automattic.com/wordpress/trunk@1401 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/upgrade-functions.php | 12 ++++++++++ wp-blog-header.php | 1 - wp-includes/functions.php | 40 +++++++++++++++++----------------- wp-settings.php | 11 +++++----- 4 files changed, 37 insertions(+), 27 deletions(-) diff --git a/wp-admin/upgrade-functions.php b/wp-admin/upgrade-functions.php index ed7f228a5d..d744ee1eae 100644 --- a/wp-admin/upgrade-functions.php +++ b/wp-admin/upgrade-functions.php @@ -841,6 +841,18 @@ function upgrade_130() { if(!$wpdb->get_var("SELECT option_id FROM $wpdb->options WHERE option_name = 'default_email_category'")) { $wpdb->query("INSERT INTO $wpdb->options (option_name, option_type, option_value, option_description, option_admin_level) VALUES('default_email_category', 1, '1', 'by default posts by email will have this category', 8)"); } + + if(!$wpdb->get_var("SELECT option_id FROM $wpdb->options WHERE option_name = 'recently_edited'")) { + $wpdb->query("INSERT INTO $wpdb->options (option_name, option_type, option_value, option_admin_level) VALUES ('recently_edited', 3, '', 8)"); + } + + maybe_add_column($wpdb->options, 'autoload', "ALTER TABLE `$wpdb->options` ADD `autoload` ENUM( 'yes', 'no' ) NOT NULL ;"); + + // Set up a few options not to load by default + $fatoptions = array( 'moderation_keys', 'recently_edited' ); + foreach ($fatoptions as $fatoption) : + $wpdb->query("UPDATE $wpdb->options SET `autoload` = 'no' WHERE option_name = '$fatoption'"); + endforeach; } ?> \ No newline at end of file diff --git a/wp-blog-header.php b/wp-blog-header.php index 684941680b..a8814cb656 100644 --- a/wp-blog-header.php +++ b/wp-blog-header.php @@ -148,7 +148,6 @@ foreach (array_merge($wpvarstoreset, $more_wpvars) as $wpvar) { if ($pagenow != 'post.php') { timer_start(); } // Update some caches. -update_user_cache(); update_category_cache(); // Call query posts to do the work. diff --git a/wp-includes/functions.php b/wp-includes/functions.php index 3af727e25a..52d5ef2e34 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -188,7 +188,7 @@ function get_userdata($userid) { function get_userdatabylogin($user_login) { global $cache_userdata, $wpdb; - if ( empty($cache_userdata["$user_login"]) ) { + if ( !empty($user_login) && empty($cache_userdata["$user_login"]) ) { $user = $wpdb->get_row("SELECT * FROM $wpdb->users WHERE user_login = '$user_login'"); $cache_userdata["$user_login"] = $user; } else { @@ -199,7 +199,7 @@ function get_userdatabylogin($user_login) { function get_userid($user_login) { global $cache_userdata, $wpdb; - if ( empty($cache_userdata["$user_login"]) ) { + if ( !empty($user_login) && empty($cache_userdata["$user_login"]) ) { $user_id = $wpdb->get_var("SELECT ID FROM $wpdb->users WHERE user_login = '$user_login'"); $cache_userdata["$user_login"] = $user_id; @@ -300,38 +300,34 @@ function url_to_postid($url = '') { function get_settings($setting) { global $wpdb, $cache_settings; - if (strstr($_SERVER['REQUEST_URI'], 'install.php')) { + if ( strstr($_SERVER['REQUEST_URI'], 'install.php') || strstr($_SERVER['REQUEST_URI'], 'upgrade.php') ) { return false; } - if ( (empty($cache_settings)) ) { - $settings = get_alloptions(); - $cache_settings = $settings; - } else { - $settings = $cache_settings; + if ( empty($cache_settings) ) { + $cache_settings = get_alloptions(); } - if ('home' == $setting && '' == $settings->home) return $settings->siteurl; + if ('home' == $setting && '' == $cache_settings->home) return $cache_settings->siteurl; - if (!isset($settings->$setting)) { - return false; + if (!isset($cache_settings->$setting)) { + return $wpdb->get_var("SELECT option_value FROM $wpdb->options WHERE option_name = '$setting'"); } else { - return stripslashes($settings->$setting); + return $cache_settings->$setting; } } function get_alloptions() { global $wpdb; - $options = $wpdb->get_results("SELECT option_name, option_value FROM $wpdb->options"); - if ($options) { + if ($options = $wpdb->get_results("SELECT option_name, option_value FROM $wpdb->options WHERE autoload = 'yes'")) { foreach ($options as $option) { // "When trying to design a foolproof system, - // never underestimate the ingenuity of the fools :)" + // never underestimate the ingenuity of the fools :)" -- Dougal if ('siteurl' == $option->option_name) $option->option_value = preg_replace('|/+$|', '', $option->option_value); if ('home' == $option->option_name) $option->option_value = preg_replace('|/+$|', '', $option->option_value); if ('category_base' == $option->option_name) $option->option_value = preg_replace('|/+$|', '', $option->option_value); - $all_options->{$option->option_name} = $option->option_value; + $all_options->{$option->option_name} = stripslashes($option->option_value); } } return $all_options; @@ -1811,10 +1807,14 @@ function update_category_cache() { function update_user_cache() { global $cache_userdata, $wpdb; - $users = $wpdb->get_results("SELECT * FROM $wpdb->users WHERE user_level > 0"); - foreach ($users as $user) { - $cache_userdata[$user->ID] = $user; - } + if ( $users = $wpdb->get_results("SELECT * FROM $wpdb->users WHERE user_level > 0") ) : + foreach ($users as $user) : + $cache_userdata[$user->ID] = $user; + endforeach; + return true; + else: + return false; + endif; } function wp_head() { diff --git a/wp-settings.php b/wp-settings.php index 0bb13e8367..e56534561f 100644 --- a/wp-settings.php +++ b/wp-settings.php @@ -47,12 +47,6 @@ if ( !(phpversion() >= '4.1') ) die( 'Your server is running PHP version ' . phpversion() . ' but WordPress requires at least 4.1' ); -$wpdb->hide_errors(); -$users = $wpdb->get_results("SELECT * FROM $wpdb->users"); -if ( !$users && !strstr($_SERVER['PHP_SELF'], 'install.php') ) - die("It doesn't look like you've installed WP yet. Try running install.php."); -$wpdb->show_errors(); - require (ABSPATH . WPINC . '/functions.php'); require (ABSPATH . WPINC . '/functions-formatting.php'); require (ABSPATH . WPINC . '/template-functions.php'); @@ -60,6 +54,11 @@ require (ABSPATH . WPINC . '/links.php'); require (ABSPATH . WPINC . '/kses.php'); require_once (ABSPATH . WPINC . '/wp-l10n.php'); +$wpdb->hide_errors(); +if ( !update_user_cache() && !strstr($_SERVER['PHP_SELF'], 'install.php') ) + die("It doesn't look like you've installed WP yet. Try running install.php."); +$wpdb->show_errors(); + if (!strstr($_SERVER['PHP_SELF'], 'install.php') && !strstr($_SERVER['PHP_SELF'], 'wp-admin/import')) { $querystring_start = '?';