Suspend cache invalidation while importing posts with WP importer

git-svn-id: http://svn.automattic.com/wordpress/trunk@9106 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2008-10-09 00:50:52 +00:00
parent cd7ea183e7
commit 9af33a74a9
3 changed files with 27 additions and 1 deletions

View File

@ -717,10 +717,12 @@ class WP_Import {
$this->import_start();
$this->get_authors_from_post();
wp_suspend_cache_invalidation(true);
$this->get_entries();
$this->process_categories();
$this->process_tags();
$result = $this->process_posts();
wp_suspend_cache_invalidation(false);
$this->backfill_parents();
$this->backfill_attachment_urls();
$this->import_end();

View File

@ -2847,4 +2847,24 @@ function wp_guess_url() {
return $url;
}
/**
* Suspend cache invalidation.
*
* Turns cache invalidation on and off. Useful during imports where you don't wont to do invalidations
* every time a post is inserted. Callers must be sure that what they are doing won't lead to an inconsistent
* cache when invalidation is suspended.
*
* @since 2.7.0
*
* @param bool $suspend Whether to suspend or enable cache invalidation
* @return bool The current suspend setting
*/
function wp_suspend_cache_invalidation($suspend = true) {
global $_wp_suspend_cache_invalidation;
$current_suspend = $_wp_suspend_cache_invalidation;
$_wp_suspend_cache_invalidation = $suspend;
return $current_suspend;
}
?>

View File

@ -2861,7 +2861,11 @@ function update_post_cache(&$posts) {
* @param int $id The Post ID in the cache to clean
*/
function clean_post_cache($id) {
global $wpdb;
global $_wp_suspend_cache_invalidation, $wpdb;
if ( !empty($_wp_suspend_cache_invalidation) )
return;
$id = (int) $id;
wp_cache_delete($id, 'posts');