Make WordPress Core

Ticket #6746: get_permalink_cached.diff

File get_permalink_cached.diff, 1.6 KB (added by filosofo, 17 years ago)
  • wp-includes/link-template.php

     
    6161        $post = &get_post($id);
    6262
    6363        if ( empty($post->ID) ) return FALSE;
     64       
     65        if ( $permalink = wp_cache_get($post->ID, 'permalinks') ) {
     66                return $permalink;
     67        }
    6468
    65         if ( $post->post_type == 'page' )
    66                 return get_page_link($post->ID, $leavename);
    67         elseif ($post->post_type == 'attachment')
    68                 return get_attachment_link($post->ID);
     69        if ( $post->post_type == 'page' ) {
     70                $permalink = get_page_link($post->ID, $leavename);
     71                wp_cache_add($post->ID, $permalink, 'permalinks');
     72                return $permalink;
     73        } elseif ($post->post_type == 'attachment') {
     74                $permalink = get_attachment_link($post->ID);
     75                wp_cache_add($post->ID, $permalink, 'permalinks');
     76                return $permalink;
     77        }
    6978
    7079        $permalink = get_option('permalink_structure');
    7180
     
    112121                );
    113122                $permalink = get_option('home') . str_replace($rewritecode, $rewritereplace, $permalink);
    114123                $permalink = user_trailingslashit($permalink, 'single');
    115                 return apply_filters('post_link', $permalink, $post);
     124                $permalink = apply_filters('post_link', $permalink, $post);
     125                wp_cache_add($post->ID, $permalink, 'permalinks');
     126                return $permalink;
    116127        } else { // if they're not using the fancy permalink option
    117128                $permalink = get_option('home') . '/?p=' . $post->ID;
    118                 return apply_filters('post_link', $permalink, $post);
     129                $permalink = apply_filters('post_link', $permalink, $post);
     130                wp_cache_add($post->ID, $permalink, 'permalinks');
     131                return $permalink;
    119132        }
    120133}
    121134