Some caching cleanups.

git-svn-id: http://svn.automattic.com/wordpress/trunk@4631 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2006-12-08 07:35:45 +00:00
parent b81bf35aad
commit 203f6c5ab4
4 changed files with 37 additions and 32 deletions

View File

@ -133,13 +133,11 @@ function wp_insert_category($catarr) {
$wpdb->query( "UPDATE $wpdb->categories SET category_nicename = '$category_nicename' WHERE cat_ID = '$cat_ID'" );
}
wp_cache_delete($cat_ID, 'category');
wp_cache_delete('get_categories', 'category');
clean_category_cache($cat_ID);
if ($update) {
do_action('edit_category', $cat_ID);
} else {
wp_cache_delete('all_category_ids', 'category');
do_action('create_category', $cat_ID);
do_action('add_category', $cat_ID);
}
@ -213,9 +211,7 @@ function wp_delete_category($cat_ID) {
wp_set_link_cats($link_id, $cats);
}
wp_cache_delete($cat_ID, 'category');
wp_cache_delete('all_category_ids', 'category');
wp_cache_delete('get_categories', 'category');
clean_category_cache($cat_ID);
do_action('delete_category', $cat_ID);
@ -487,7 +483,6 @@ function wp_set_link_cats($link_ID = 0, $link_categories = array()) {
do_action('edit_category', $cat_id);
}
do_action('edit_link', $link_ID);
} // wp_set_link_cats()
function post_exists($title, $content = '', $post_date = '') {

View File

@ -430,18 +430,13 @@ function wp_set_comment_status($comment_id, $comment_status) {
return false;
}
if ( $wpdb->query($query) ) {
do_action('wp_set_comment_status', $comment_id, $comment_status);
$comment = get_comment($comment_id);
$comment_post_ID = $comment->comment_post_ID;
$c = $wpdb->get_row("SELECT count(*) as c FROM {$wpdb->comments} WHERE comment_post_ID = '$comment_post_ID' AND comment_approved = '1'");
if ( is_object($c) )
$wpdb->query("UPDATE $wpdb->posts SET comment_count = '$c->c' WHERE ID = '$comment_post_ID'");
return true;
} else {
if ( !$wpdb->query($query) )
return false;
}
do_action('wp_set_comment_status', $comment_id, $comment_status);
$comment = get_comment($comment_id);
wp_update_comment_count($comment->comment_post_ID);
return true;
}
@ -490,6 +485,15 @@ function wp_update_comment_count($post_id) {
$count = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_post_ID = '$post_id' AND comment_approved = '1'");
$wpdb->query("UPDATE $wpdb->posts SET comment_count = $count WHERE ID = '$post_id'");
$comment_count_cache[$post_id] = $count;
$post = get_post($post_id);
if ( 'page' == $post->post_type )
clean_page_cache( $post_id );
else
clean_post_cache( $post_id );
do_action('edit_post', $post_id);
return true;
}

View File

@ -519,10 +519,16 @@ function update_post_cache(&$posts) {
}
function clean_post_cache($id) {
global $post_cache, $blog_id;
global $post_cache, $post_meta_cache, $category_cache, $blog_id;
if ( isset( $post_cache[$blog_id][$id] ) )
unset( $post_cache[$blog_id][$id] );
if ( isset ($post_meta_cache[$blog_id][$id] ) )
unset( $post_meta_cache[$blog_id][$id] );
if ( isset( $category_cache[$blog_id][$id]) )
unset ( $category_cache[$blog_id][$id] );
}
function update_page_cache(&$pages) {
@ -537,12 +543,15 @@ function update_page_cache(&$pages) {
}
}
function clean_page_cache($id) {
global $page_cache, $blog_id;
if ( isset( $page_cache[$blog_id][$id] ) )
unset( $page_cache[$blog_id][$id] );
wp_cache_delete($id, 'pages');
wp_cache_delete( 'all_page_ids', 'pages' );
wp_cache_delete( 'get_pages', 'page' );
}
function update_post_category_cache($post_ids) {
@ -649,6 +658,12 @@ function update_category_cache() {
return true;
}
function clean_category_cache($id) {
wp_cache_delete($id, 'category');
wp_cache_delete('all_category_ids', 'category');
wp_cache_delete('get_categories', 'category');
}
/*
add_query_arg: Returns a modified querystring by adding
a single key & value or an associative array.

View File

@ -438,8 +438,7 @@ function wp_delete_post($postid = 0) {
$wpdb->query("DELETE FROM $wpdb->postmeta WHERE post_id = $postid");
if ( 'page' == $post->post_type ) {
wp_cache_delete( 'all_page_ids', 'pages' );
wp_cache_delete( 'get_pages', 'page' );
clean_page_cache($postid);
$wp_rewrite->flush_rules();
}
@ -650,7 +649,7 @@ function wp_insert_post($postarr = array()) {
if ( 'page' == $post_type ) {
clean_page_cache($post_ID);
wp_cache_delete($post_ID, 'pages');
$wp_rewrite->flush_rules();
} else {
clean_post_cache($post_ID);
}
@ -689,10 +688,6 @@ function wp_insert_post($postarr = array()) {
wp_schedule_single_event(time(), 'do_pings');
}
} else if ($post_type == 'page') {
wp_cache_delete( 'all_page_ids', 'pages' );
wp_cache_delete( 'get_pages', 'page' );
$wp_rewrite->flush_rules();
if ( !empty($page_template) )
if ( ! update_post_meta($post_ID, '_wp_page_template', $page_template))
add_post_meta($post_ID, '_wp_page_template', $page_template, true);
@ -816,13 +811,9 @@ function wp_set_post_categories($post_ID = 0, $post_categories = array()) {
foreach ( $all_affected_cats as $cat_id ) {
$count = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->post2cat, $wpdb->posts WHERE $wpdb->posts.ID=$wpdb->post2cat.post_id AND post_status = 'publish' AND post_type = 'post' AND category_id = '$cat_id'");
$wpdb->query("UPDATE $wpdb->categories SET category_count = '$count' WHERE cat_ID = '$cat_id'");
wp_cache_delete($cat_id, 'category');
clean_category_cache($cat_id);
do_action('edit_category', $cat_id);
}
wp_cache_delete('get_categories', 'category');
do_action('edit_post', $post_ID);
} // wp_set_post_categories()
//