Ticket #28664: 28664-load_alloptions_cache_handling.diff
File 28664-load_alloptions_cache_handling.diff, 1.7 KB (added by , 10 years ago) |
---|
-
src/wp-includes/option.php
158 158 function wp_load_alloptions() { 159 159 global $wpdb; 160 160 161 if ( !defined( 'WP_INSTALLING' ) || !is_multisite() ) 162 $alloptions = wp_cache_get( 'alloptions', 'options' ); 163 else 161 $use_cache = !defined( 'WP_INSTALLING' ) || !is_multisite(); 162 163 if ( $use_cache ) { 164 $cache_data = wp_cache_get( 'alloptions', 'options' ); 165 $alloptions = $cache_data; 166 } else { 164 167 $alloptions = false; 168 } 165 169 166 if ( !$alloptions ) { 170 // make sure the cached object is an array; on rare events this can be a zero 171 if ( ! is_array($alloptions) ) { 172 167 173 $suppress = $wpdb->suppress_errors(); 168 174 if ( !$alloptions_db = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options WHERE autoload = 'yes'" ) ) 169 175 $alloptions_db = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options" ); 170 176 $wpdb->suppress_errors($suppress); 177 171 178 $alloptions = array(); 172 179 foreach ( (array) $alloptions_db as $o ) { 173 $alloptions[ $o->option_name] = $o->option_value;180 $alloptions[ $o->option_name ] = $o->option_value; 174 181 } 175 if ( !defined( 'WP_INSTALLING' ) || !is_multisite() ) 176 wp_cache_add( 'alloptions', $alloptions, 'options' ); 182 183 if ( $use_cache ) { 184 $cache_added = false; 185 186 // if original result was a false, add the data: 187 if ( false === $cache_data ) { 188 $cache_added = wp_cache_add( 'alloptions', $alloptions, 'options' ); 189 } 190 191 // if original result was 'data' or adding failed: 192 if ( false === $cache_added ) { 193 wp_cache_set( 'alloptions', $alloptions, 'options' ); 194 } 195 } 177 196 } 178 197 179 198 return $alloptions;