Making WordPress.org

Changeset 13759


Ignore:
Timestamp:
05/30/2024 04:48:38 AM (2 years ago)
Author:
dd32
Message:

Theme Directory: API: Remove a layer of caching, as these caches wrap other functions that have caching.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/class-themes-api.php

    r12632 r13759  
    223223         */
    224224        public function hot_tags() {
    225                 $cache_key = sanitize_key( __METHOD__ );
    226                 if ( false === ( $this->response = wp_cache_get( $cache_key, $this->cache_group ) ) ) {
    227                         $tags = get_tags( array(
    228                                 'orderby'    => 'count',
    229                                 'order'      => 'DESC',
    230                                 'hide_empty' => false,
    231                         ) );
    232 
    233                         // Format in the API representation.
    234                         foreach ( $tags as $tag ) {
    235                                 $this->response[ $tag->slug ] = array(
    236                                         'name'  => $tag->name,
    237                                         'slug'  => $tag->slug,
    238                                         'count' => $tag->count,
    239                                 );
    240                         }
    241 
    242                         wp_cache_add( $cache_key, $this->response, $this->cache_group, $this->cache_life );
     225                $tags = get_tags( array(
     226                        'orderby'    => 'count',
     227                        'order'      => 'DESC',
     228                        'hide_empty' => false,
     229                ) );
     230
     231                // Format in the API representation.
     232                foreach ( $tags as $tag ) {
     233                        $this->response[ $tag->slug ] = array(
     234                                'name'  => $tag->name,
     235                                'slug'  => $tag->slug,
     236                                'count' => $tag->count,
     237                        );
    243238                }
    244239
     
    481476                $this->fields = array_merge( $this->fields, $defaults, (array) $this->request->fields );
    482477
    483                 // If there is a cached result, return that.
    484                 $cache_key = sanitize_key( __METHOD__ . ':' . get_locale() . ':' . $this->request->slug . ':' . md5( serialize( $this->fields ) ) );
    485                 if ( false !== ( $this->response = wp_cache_get( $cache_key, $this->cache_group ) ) && empty( $this->request->cache_buster ) ) {
    486                         return;
    487                 }
    488 
    489478                if ( !empty( $post ) && 'repopackage' == $post->post_type && $this->request->slug === $post->post_name ) {
    490479                        $this->response = $this->fill_theme( $post );
     
    503492                        }
    504493                }
    505 
    506                 wp_cache_set( $cache_key, $this->response, $this->cache_group, $this->cache_life );
    507494        }
    508495
     
    551538                $this->fields = array_merge( $this->fields, $defaults, $this->request->fields );
    552539
    553                 // If there is a cached result, return that.
    554                 $cache_key = sanitize_key( __METHOD__ . ':' . get_locale() . ':' . md5( serialize( $this->request ) . serialize( $this->fields ) ) );
    555                 if ( false !== ( $this->response = wp_cache_get( $cache_key, $this->cache_group ) ) && empty( $this->request->cache_buster ) ) {
    556                         return;
    557                 }
    558 
    559540                $this->result = $this->perform_wp_query();
    560541
     
    576557                        $this->response->themes[] = $this->fill_theme( $theme );
    577558                }
    578 
    579                 wp_cache_set( $cache_key, $this->response, $this->cache_group, $this->cache_life );
    580559        }
    581560
     
    678657                        'post_type'      => 'theme_shop',
    679658                        'posts_per_page' => -1,
     659                        // NOTE: This rand() disables WP_Query caching.
    680660                        'orderby'        => 'rand(' . gmdate('YmdH') . ')',
    681661                ) );
     
    704684         */
    705685        public function fill_theme( $theme ) {
    706                 // If there is a cached theme for the current locale, return that.
    707                 $cache_key = sanitize_key( implode( '-', array( $theme->post_name, md5( serialize( $this->fields ) ), get_locale() ) ) );
    708                 if ( false !== ( $phil = wp_cache_get( $cache_key, $this->cache_group ) ) && empty( $this->request->cache_buster ) ) {
    709                         return $phil;
    710                 }
    711 
    712686                global $wpdb;
    713687
     
    944918                }
    945919
    946                 wp_cache_set( $cache_key, $phil, $this->cache_group, $this->cache_life );
    947 
    948920                return $phil;
    949921        }
Note: See TracChangeset for help on using the changeset viewer.