Changeset 57029
- Timestamp:
- 10/30/2023 10:56:25 PM (9 months ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/option.php
r57013 r57029 262 262 $alloptions = wp_load_alloptions(); 263 263 $cached_options = wp_cache_get_multiple( $options, 'options' ); 264 265 266 267 264 268 265 269 // Filter options that are not in the cache. 266 270 $options_to_prime = array(); 267 271 foreach ( $options as $option ) { 268 if ( ( ! isset( $cached_options[ $option ] ) || ! $cached_options[ $option ] ) && ! isset( $alloptions[ $option ] ) ) { 272 if ( 273 ( ! isset( $cached_options[ $option ] ) || false === $cached_options[ $option ] ) 274 && ! isset( $alloptions[ $option ] ) 275 && ! isset( $notoptions[ $option ] ) 276 ) { 269 277 $options_to_prime[] = $option; 270 278 } … … 289 297 $options_found = array(); 290 298 foreach ( $results as $result ) { 291 $options_found[ $result->option_name ] = maybe_unserialize( $result->option_value ); 299 /* 300 * The cache is primed with the raw value (i.e. not maybe_unserialized). 301 * 302 * `get_option()` will handle unserializing the value as needed. 303 */ 304 $options_found[ $result->option_name ] = $result->option_value; 292 305 } 293 306 wp_cache_set_multiple( $options_found, 'options' ); … … 299 312 300 313 $options_not_found = array_diff( $options_to_prime, array_keys( $options_found ) ); 301 302 $notoptions = wp_cache_get( 'notoptions', 'options' );303 304 if ( ! is_array( $notoptions ) ) {305 $notoptions = array();306 }307 314 308 315 // Add the options that were not found to the cache. -
trunk/tests/phpunit/tests/option/wpPrimeOptionCaches.php
r57013 r57029 42 42 foreach ( $options_to_prime as $option ) { 43 43 $this->assertSame( 44 44 45 wp_cache_get( $option, 'options' ), 45 get_option( $option ),46 46 "$option was not primed in the 'options' cache group." 47 47 ); 48 48 49 $this->assertFalse( 50 wp_cache_get( $option, 'notoptions' ), 51 get_option( $option ), 52 "$option was primed in the 'notoptions' cache group." 49 $new_notoptions = wp_cache_get( $option, 'notoptions' ); 50 if ( ! is_array( $new_notoptions ) ) { 51 $new_notoptions = array(); 52 } 53 $this->assertArrayNotHasKey( 54 $option, 55 $new_notoptions, 56 "$option was primed in the 'notoptions' cache." 53 57 ); 54 58 } … … 63 67 64 68 /** 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 65 128 * Tests wp_prime_option_caches() with options that do not exist in the database. 66 129 * 67 130 * @ticket 58962 131 68 132 */ 69 133 public function test_wp_prime_option_caches_with_nonexistent_options() { … … 97 161 $this->assertArrayHasKey( $option, $new_notoptions, "$option was not added to the notoptions cache." ); 98 162 } 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 99 181 } 100 182 … … 103 185 * 104 186 * @ticket 58962 187 105 188 */ 106 189 public function test_wp_prime_option_caches_with_empty_array() { … … 108 191 $notoptions = wp_cache_get( 'notoptions', 'options' ); 109 192 193 110 194 wp_prime_option_caches( array() ); 111 195 112 196 $this->assertSame( $alloptions, wp_cache_get( 'alloptions', 'options' ), 'The alloptions cache was modified.' ); 113 197 $this->assertSame( $notoptions, wp_cache_get( 'notoptions', 'options' ), 'The notoptions cache was modified.' ); 198 199 200 201 202 203 204 114 205 } 115 206 … … 118 209 * 119 210 * @ticket 58962 211 120 212 */ 121 213 public function test_wp_prime_option_caches_handles_empty_notoptions_cache() { … … 127 219 $this->assertIsArray( $notoptions, 'The notoptions cache should be an array.' ); 128 220 $this->assertArrayHasKey( 'nonexistent_option', $notoptions, 'nonexistent_option was not added to notoptions.' ); 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 129 460 } 130 461 } -
trunk/tests/phpunit/tests/option/wpPrimeOptionCachesByGroup.php
r57013 r57029 48 48 wp_prime_option_caches_by_group( 'group1' ); 49 49 50 // Check that options are now in the cache. 51 $this->assertSame( get_option( 'option1' ), wp_cache_get( 'option1', 'options' ), 'option1\'s cache was not primed.' ); 52 $this->assertSame( get_option( 'option2' ), wp_cache_get( 'option2', 'options' ), 'option2\'s cache was not primed.' ); 50 /* 51 * Check that options are now in the cache. 52 * 53 * Repeat the string here rather than using get_option as get_option 54 * will prime the cache before the call to wp_cache_get if the option 55 * is not in the cache. Thus causing the tests to pass when they should 56 * fail. 57 */ 58 $this->assertSame( 'value_option1', wp_cache_get( 'option1', 'options' ), 'option1\'s cache was not primed.' ); 59 $this->assertSame( 'value_option2', wp_cache_get( 'option2', 'options' ), 'option2\'s cache was not primed.' ); 53 60 54 61 // Make sure option3 is still not in cache.
Note: See TracChangeset
for help on using the changeset viewer.