Defer comment counting. Props tellyworth. fixes #5557
git-svn-id: https://develop.svn.wordpress.org/trunk@6532 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
cdbb434e6a
commit
d633240113
|
@ -376,7 +376,9 @@ class WP_Import {
|
|||
$cat_index++;
|
||||
}
|
||||
|
||||
if ($post_id = post_exists($post_title, '', $post_date)) {
|
||||
$post_exists = post_exists($post_title, '', $post_date);
|
||||
|
||||
if ( $post_exists ) {
|
||||
echo '<li>';
|
||||
printf(__('Post <i>%s</i> already exists.'), stripslashes($post_title));
|
||||
} else {
|
||||
|
@ -475,7 +477,8 @@ class WP_Import {
|
|||
$comment_type = $this->get_tag( $comment, 'wp:comment_type');
|
||||
$comment_parent = $this->get_tag( $comment, 'wp:comment_parent');
|
||||
|
||||
if ( !comment_exists($comment_author, $comment_date) ) {
|
||||
// if this is a new post we can skip the comment_exists() check
|
||||
if ( !$post_exists || !comment_exists($comment_author, $comment_date) ) {
|
||||
$commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_url', 'comment_author_email', 'comment_author_IP', 'comment_date', 'comment_date_gmt', 'comment_content', 'comment_approved', 'comment_type', 'comment_parent');
|
||||
wp_insert_comment($commentdata);
|
||||
$num_comments++;
|
||||
|
@ -648,35 +651,45 @@ class WP_Import {
|
|||
return apply_filters('import_attachment_size_limit', 0);
|
||||
}
|
||||
|
||||
|
||||
function import($id, $fetch_attachments = false) {
|
||||
$this->id = (int) $id;
|
||||
$this->fetch_attachments = ($this->allow_fetch_attachments() && (bool) $fetch_attachments);
|
||||
|
||||
add_filter('import_post_meta_key', array($this, 'is_valid_meta_key'));
|
||||
function import_start() {
|
||||
wp_defer_term_counting(true);
|
||||
wp_defer_comment_counting(true);
|
||||
do_action('import_start');
|
||||
$file = get_attached_file($this->id);
|
||||
$this->import_file($file);
|
||||
do_action('import_end');
|
||||
}
|
||||
|
||||
function import_file($file) {
|
||||
$this->file = $file;
|
||||
|
||||
$this->get_authors_from_post();
|
||||
wp_defer_term_counting(true);
|
||||
$this->get_entries();
|
||||
$this->process_categories();
|
||||
$this->process_tags();
|
||||
$result = $this->process_posts();
|
||||
$this->backfill_parents();
|
||||
$this->backfill_attachment_urls();
|
||||
function import_end() {
|
||||
do_action('import_end');
|
||||
|
||||
// clear the caches after backfilling
|
||||
foreach ($this->post_ids_processed as $post_id)
|
||||
clean_post_cache($post_id);
|
||||
|
||||
wp_defer_term_counting(false);
|
||||
wp_defer_comment_counting(false);
|
||||
}
|
||||
|
||||
function import($id, $fetch_attachments = false) {
|
||||
$this->id = (int) $id;
|
||||
$this->fetch_attachments = ($this->allow_fetch_attachments() && (bool) $fetch_attachments);
|
||||
|
||||
add_filter('import_post_meta_key', array($this, 'is_valid_meta_key'));
|
||||
$file = get_attached_file($this->id);
|
||||
$this->import_file($file);
|
||||
}
|
||||
|
||||
function import_file($file) {
|
||||
$this->file = $file;
|
||||
|
||||
$this->import_start();
|
||||
$this->get_authors_from_post();
|
||||
$this->get_entries();
|
||||
$this->process_categories();
|
||||
$this->process_tags();
|
||||
$result = $this->process_posts();
|
||||
$this->backfill_parents();
|
||||
$this->backfill_attachment_urls();
|
||||
$this->import_end();
|
||||
|
||||
if ( is_wp_error( $result ) )
|
||||
return $result;
|
||||
}
|
||||
|
|
|
@ -491,8 +491,41 @@ function wp_update_comment($commentarr) {
|
|||
return $rval;
|
||||
}
|
||||
|
||||
function wp_defer_comment_counting($defer=NULL) {
|
||||
static $_defer = false;
|
||||
|
||||
function wp_update_comment_count($post_id) {
|
||||
if ( is_bool($defer) ) {
|
||||
$_defer = $defer;
|
||||
// flush any deferred counts
|
||||
if ( !$defer )
|
||||
wp_update_comment_count( NULL, true );
|
||||
}
|
||||
|
||||
return $_defer;
|
||||
}
|
||||
|
||||
function wp_update_comment_count($post_id, $do_deferred=false) {
|
||||
static $_deferred = array();
|
||||
|
||||
if ( $do_deferred ) {
|
||||
$_deferred = array_unique($_deferred);
|
||||
foreach ( $_deferred as $i => $_post_id ) {
|
||||
wp_update_comment_count_now($_post_id);
|
||||
unset( $_deferred[$i] );
|
||||
}
|
||||
}
|
||||
|
||||
if ( wp_defer_comment_counting() ) {
|
||||
$_deferred[] = $post_id;
|
||||
return true;
|
||||
}
|
||||
elseif ( $post_id ) {
|
||||
return wp_update_comment_count_now($post_id);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function wp_update_comment_count_now($post_id) {
|
||||
global $wpdb;
|
||||
$post_id = (int) $post_id;
|
||||
if ( !$post_id )
|
||||
|
|
Loading…
Reference in New Issue