Changeset 48532
- Timestamp:
- 07/21/2020 01:55:45 PM (6 months ago)
- Location:
- trunk
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/sitemaps/class-wp-sitemaps-index.php
r48470 r48532 26 26 27 27 /** 28 * Maximum number of sitemaps to include in an index. 29 * 30 * @sincee 5.5.0 31 * 32 * @var int Maximum number of sitemaps. 33 */ 34 private $max_sitemaps = 50000; 35 36 /** 28 37 * WP_Sitemaps_Index constructor. 29 38 * … … 48 57 $providers = $this->registry->get_sitemaps(); 49 58 /* @var WP_Sitemaps_Provider $provider */ 50 foreach ( $providers as $ provider ) {59 foreach ( $providers as $name => $provider ) { 51 60 $sitemap_entries = $provider->get_sitemap_entries(); 52 61 … … 58 67 // Using array_push is more efficient than array_merge in a loop. 59 68 array_push( $sitemaps, ...$sitemap_entries ); 69 if ( count( $sitemaps ) >= $this->max_sitemaps ) { 70 break; 71 } 60 72 } 61 73 62 return $sitemaps;74 return array_slice( $sitemaps, 0, $this->max_sitemaps, true ); 63 75 } 64 76 -
trunk/src/wp-includes/sitemaps/class-wp-sitemaps-registry.php
r48098 r48532 24 24 */ 25 25 private $sitemaps = array(); 26 27 /**28 * Maximum number of sitemaps to include in an index.29 *30 * @sincee 5.5.031 *32 * @var int Maximum number of sitemaps.33 */34 private $max_sitemaps = 50000;35 26 36 27 /** … … 70 61 71 62 /** 72 * Lists all registered sitemaps.63 * Returns all registered sitemap providers. 73 64 * 74 65 * @since 5.5.0 … … 77 68 */ 78 69 public function get_sitemaps() { 79 $total_sitemaps = count( $this->sitemaps );80 81 if ( $total_sitemaps > $this->max_sitemaps ) {82 return array_slice( $this->sitemaps, 0, $this->max_sitemaps, true );83 }84 85 70 return $this->sitemaps; 86 71 } -
trunk/tests/phpunit/includes/bootstrap.php
r48115 r48532 163 163 require __DIR__ . '/class-wp-sitemaps-test-provider.php'; 164 164 require __DIR__ . '/class-wp-sitemaps-empty-test-provider.php'; 165 require __DIR__ . '/class-wp-sitemaps-large-test-provider.php'; 165 166 166 167 /** -
trunk/tests/phpunit/tests/sitemaps/sitemaps-index.php
r48072 r48532 19 19 $sitemap_index = new WP_Sitemaps_Index( $registry ); 20 20 $this->assertCount( 24, $sitemap_index->get_sitemap_list() ); 21 } 22 23 /** 24 * Test that a sitemap index won't contain more than 50000 sitemaps. 25 * 26 * @ticket 50666 27 */ 28 public function test_get_sitemap_list_limit() { 29 $registry = new WP_Sitemaps_Registry(); 30 31 // add 3 providers, which combined produce more than the maximum 50000 sitemaps in the index. 32 $registry->add_sitemap( 'provider_1', new WP_Sitemaps_Large_Test_Provider( 25000 ) ); 33 $registry->add_sitemap( 'provider_2', new WP_Sitemaps_Large_Test_Provider( 25000 ) ); 34 $registry->add_sitemap( 'provider_3', new WP_Sitemaps_Large_Test_Provider( 25000 ) ); 35 36 $count = 0; 37 foreach ( $registry->get_sitemaps() as $provider ) { 38 $count += count( $provider->get_url_list( 1 ) ); 39 } 40 $this->assertGreaterThan( 50000, $count ); 41 42 $sitemap_index = new WP_Sitemaps_Index( $registry ); 43 $this->assertCount( 50000, $sitemap_index->get_sitemap_list() ); 21 44 } 22 45
Note: See TracChangeset
for help on using the changeset viewer.