Changeset 12846
- Timestamp:
- 08/17/2023 05:16:41 AM (15 months ago)
- Location:
- sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/class-status-transitions.php
r12594 r12846 9 9 use WordPressdotorg\Plugin_Directory\Email\Plugin_Rejected as Plugin_Rejected_Email; 10 10 use WordPressdotorg\Plugin_Directory\Admin\Metabox\Reviewer as Reviewer_Metabox; 11 use WordPressdotorg\Plugin_Directory\Jobs\API_Update_Updater; 12 use WordPressdotorg\Plugin_Directory\Standalone\Plugins_Info_API; 11 13 12 14 /** … … 164 166 update_post_meta( $post->ID, "_{$new_status}", strtotime( $post->post_modified_gmt ) ); 165 167 } 168 169 // Clear any relevant caches. 170 $this->flush_caches( $post ); 166 171 } 167 172 … … 377 382 Reviewer_Metabox::set_reviewer( $post, false, false ); 378 383 } 384 385 /** 386 * Flush the caches for the plugin. 387 */ 388 protected function flush_caches( $post ) { 389 // Update the API endpoints with the new data 390 API_Update_Updater::update_single_plugin( $post->post_name ); 391 Plugins_Info_API::flush_plugin_information_cache( $post->post_name ); 392 } 379 393 } -
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/cli/class-import.php
r12715 r12846 9 9 use WordPressdotorg\Plugin_Directory\Email\Release_Confirmation as Release_Confirmation_Email; 10 10 use WordPressdotorg\Plugin_Directory\Readme\Parser; 11 use WordPressdotorg\Plugin_Directory\Standalone\Plugins_Info_API; 11 12 use WordPressdotorg\Plugin_Directory\Template; 12 13 use WordPressdotorg\Plugin_Directory\Tools; … … 370 371 // Ensure that the API gets the updated data 371 372 API_Update_Updater::update_single_plugin( $plugin->post_name ); 373 Plugins_Info_API::flush_plugin_information_cache( $plugin->post_name ); 372 374 373 375 // Import Tide data -
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/jobs/class-meta-sync.php
r10230 r12846 3 3 4 4 use WordPressdotorg\Plugin_Directory\Plugin_Directory; 5 use WordPressdotorg\Plugin_Directory\Standalone\Plugins_Info_API; 5 6 6 7 /** … … 182 183 // Update the API endpoints with the new data 183 184 API_Update_Updater::update_single_plugin( $row->post_name ); 185 Plugins_Info_API::flush_plugin_information_cache( $row->post_name ); 184 186 185 187 if ( $i % 100 === 0 ) { -
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/standalone/class-plugins-info-api.php
r12421 r12846 2 2 namespace WordPressdotorg\Plugin_Directory\Standalone; 3 3 4 // The API caches here expire every 6-7 hours, avoids cache races when multiple change at the same time.5 define( 'API_CACHE_EXPIRY', 6 * 60 * 60 + rand( 0, 60 * 60 ) );6 4 class Plugins_Info_API { 7 5 8 const CACHE_GROUP = 'plugin_api_info'; 9 const CACHE_EXPIRY = API_CACHE_EXPIRY; 6 const CACHE_GROUP = 'plugin_api_info'; 7 const CACHE_EXPIRY = 21600; // 6 hour cache, wporg_object_cache will spread this out. 8 const LONG_CACHE_EXPIRY = 86400; // 24 hour cache, wporg_object_cache will spread this out. 10 9 11 10 protected $format = 'json'; … … 106 105 } 107 106 108 if ( false === ( $response = wp_cache_get( $cache_key = $this->plugin_information_cache_key( $request ), self::CACHE_GROUP ) ) ) { 107 // Short circuit for invalid slugs. 108 if ( ! $request->slug || ! preg_match( '/^[a-z0-9-]+$/', $request->slug ) ) { 109 $response = [ 110 'error' => 'Invalid plugin slug.' 111 ]; 112 } elseif ( false === ( $response = wp_cache_get( $cache_key = $this->plugin_information_cache_key( $request ), self::CACHE_GROUP ) ) ) { 109 113 $response = $this->internal_rest_api_call( 'plugins/v1/plugin/' . $request->slug, array( 'locale' => $request->locale ) ); 110 114 … … 113 117 'error' => 'Plugin not found.' 114 118 ]; 115 wp_cache_set( $cache_key, $response, self::CACHE_GROUP, 15 * 60 ); // shorter TTL for missing/erroring plugins.119 wp_cache_set( $cache_key, $response, self::CACHE_GROUP, self::LONG_CACHE_EXPIRY * 2 ); // Not found, twice as long as normal. 116 120 } else { 117 121 $response = $response->data; 118 wp_cache_set( $cache_key, $response, self::CACHE_GROUP, self:: CACHE_EXPIRY );122 wp_cache_set( $cache_key, $response, self::CACHE_GROUP, self::LONG_CACHE_EXPIRY ); 119 123 } 120 124 } … … 145 149 return 'plugin_information:' 146 150 . ( strlen( $request->slug ) > 200 ? 'md5:' . md5( $request->slug ) : $request->slug ) 147 . ':' . ( $request->locale ?: 'en_US' ); 151 . ':' . strtolower( $request->locale ?: 'en_US' ); 152 } 153 154 /** 155 * Flush the cache for the plugin_information cache. 156 * 157 * @param string $slug The slug of the plugin to flush the cache for. 158 */ 159 public static function flush_plugin_information_cache( $slug ) { 160 foreach ( get_available_languages() as $locale ) { 161 wp_cache_delete( 162 self::plugin_information_cache_key( 163 (object) compact( 'slug', 'locale' ) 164 ), 165 self::CACHE_GROUP 166 ); 167 } 148 168 } 149 169
Note: See TracChangeset
for help on using the changeset viewer.