Make WordPress Core

Ticket #18356: 18356.3.diff

File 18356.3.diff, 1.7 KB (added by MikeHansenMe, 10 years ago)

Refreshed and minor code cleanup

  • src/wp-includes/bookmark.php

     
    118118        global $wpdb;
    119119
    120120        $defaults = array(
    121                 'orderby' => 'name', 'order' => 'ASC',
    122                 'limit' => -1, 'category' => '',
    123                 'category_name' => '', 'hide_invisible' => 1,
    124                 'show_updated' => 0, 'include' => '',
    125                 'exclude' => '', 'search' => ''
     121                'orderby'        => 'name',
     122                'order'          => 'ASC',
     123                'limit'          => -1,
     124                'category'       => '',
     125                'category_name'  => '',
     126                'hide_invisible' => 1,
     127                'show_updated'   => 0,
     128                'include'        => '',
     129                'exclude'        => '',
     130                'search'         => '',
     131                'expire'         => 60
    126132        );
    127133
    128134        $r = wp_parse_args( $args, $defaults );
    129135
    130136        $key = md5( serialize( $r ) );
    131         if ( $cache = wp_cache_get( 'get_bookmarks', 'bookmark' ) ) {
     137        if ( 'rand' == $orderby ) {
     138                if ( $results = wp_cache_get( $key, 'get_bookmarks_rand' ) ) {
     139                        return apply_filters( 'get_bookmarks', $results, $r );
     140                }
     141        } elseif ( $cache = wp_cache_get( 'get_bookmarks', 'bookmark' ) ) {
    132142                if ( is_array( $cache ) && isset( $cache[ $key ] ) ) {
    133143                        $bookmarks = $cache[ $key ];
    134144                        /**
     
    285295
    286296        $results = $wpdb->get_results( $query );
    287297
    288         $cache[ $key ] = $results;
    289         wp_cache_set( 'get_bookmarks', $cache, 'bookmark' );
     298        if ( 'rand()' == $orderby ) {
     299                wp_cache_set( $key, $results, 'get_bookmarks_rand', $expire );
     300        } else {
     301                $cache[$key] = $results;
     302                wp_cache_set( 'get_bookmarks', $cache, 'bookmark' );
     303        }
    290304
    291305        /** This filter is documented in wp-includes/bookmark.php */
    292306        return apply_filters( 'get_bookmarks', $results, $r );