Caching for get_bookmarks
git-svn-id: http://svn.automattic.com/wordpress/trunk@4520 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
e05b055337
commit
b7d514be34
|
@ -19,7 +19,7 @@ function get_bookmark($bookmark_id, $output = OBJECT) {
|
|||
|
||||
// Deprecate
|
||||
function get_link($bookmark_id, $output = OBJECT) {
|
||||
return get_bookmark($bookmark_id, $output);
|
||||
return get_bookmark($bookmark_id, $output);
|
||||
}
|
||||
|
||||
function get_bookmarks($args = '') {
|
||||
|
@ -35,6 +35,11 @@ function get_bookmarks($args = '') {
|
|||
$r = array_merge($defaults, $r);
|
||||
extract($r);
|
||||
|
||||
$key = md5( serialize( $r ) );
|
||||
if ( $cache = wp_cache_get( 'get_bookmarks', 'bookmark' ) )
|
||||
if ( isset( $cache[ $key ] ) )
|
||||
return apply_filters('get_bookmarks', $cache[ $key ], $r );
|
||||
|
||||
$inclusions = '';
|
||||
if ( !empty($include) ) {
|
||||
$exclude = ''; //ignore exclude, category, and category_name params if using include
|
||||
|
@ -50,7 +55,7 @@ function get_bookmarks($args = '') {
|
|||
}
|
||||
}
|
||||
}
|
||||
if (!empty($inclusions))
|
||||
if (!empty($inclusions))
|
||||
$inclusions .= ')';
|
||||
|
||||
$exclusions = '';
|
||||
|
@ -65,9 +70,9 @@ function get_bookmarks($args = '') {
|
|||
}
|
||||
}
|
||||
}
|
||||
if (!empty($exclusions))
|
||||
if (!empty($exclusions))
|
||||
$exclusions .= ')';
|
||||
|
||||
|
||||
if ( ! empty($category_name) ) {
|
||||
if ( $cat_id = $wpdb->get_var("SELECT cat_ID FROM $wpdb->categories WHERE cat_name='$category_name' LIMIT 1") )
|
||||
$category = $cat_id;
|
||||
|
@ -87,7 +92,7 @@ function get_bookmarks($args = '') {
|
|||
}
|
||||
}
|
||||
if (!empty($category_query)) {
|
||||
$category_query .= ')';
|
||||
$category_query .= ')';
|
||||
$join = " LEFT JOIN $wpdb->link2cat ON ($wpdb->links.link_id = $wpdb->link2cat.link_id) ";
|
||||
}
|
||||
|
||||
|
@ -128,7 +133,18 @@ function get_bookmarks($args = '') {
|
|||
$query .= " LIMIT $limit";
|
||||
|
||||
$results = $wpdb->get_results($query);
|
||||
|
||||
$cache[ $key ] = $results;
|
||||
wp_cache_set( 'get_bookmarks', $cache, 'bookmark' );
|
||||
|
||||
return apply_filters('get_bookmarks', $results, $r);
|
||||
}
|
||||
|
||||
function delete_get_bookmark_cache() {
|
||||
wp_cache_delete( 'get_bookmarks', 'bookmark' );
|
||||
}
|
||||
add_action( 'add_link', 'delete_get_bookmark_cache' );
|
||||
add_action( 'edit_link', 'delete_get_bookmark_cache' );
|
||||
add_action( 'delete_link', 'delete_get_bookmark_cache' );
|
||||
|
||||
?>
|
Loading…
Reference in New Issue