Ticket #5557: defer-comment-counts-r6528-2.patch
File defer-comment-counts-r6528-2.patch, 3.6 KB (added by , 17 years ago) |
---|
-
wordpress/wp-includes/comment.php
491 491 return $rval; 492 492 } 493 493 494 function wp_defer_comment_counting($defer=NULL) { 495 static $_defer = false; 496 497 if ( is_bool($defer) ) { 498 $_defer = $defer; 499 // flush any deferred counts 500 if ( !$defer ) 501 wp_update_comment_count( NULL, true ); 502 } 503 504 return $_defer; 505 } 494 506 495 function wp_update_comment_count($post_id) { 507 function wp_update_comment_count($post_id, $do_deferred=false) { 508 static $_deferred = array(); 509 510 if ( $do_deferred ) { 511 $_deferred = array_unique($_deferred); 512 foreach ( $_deferred as $i => $_post_id ) { 513 wp_update_comment_count_now($_post_id); 514 unset( $_deferred[$i] ); 515 } 516 } 517 518 if ( wp_defer_comment_counting() ) { 519 $_deferred[] = $post_id; 520 return true; 521 } 522 elseif ( $post_id ) { 523 return wp_update_comment_count_now($post_id); 524 } 525 526 } 527 528 function wp_update_comment_count_now($post_id) { 496 529 global $wpdb; 497 530 $post_id = (int) $post_id; 498 531 if ( !$post_id ) -
wordpress/wp-admin/import/wordpress.php
475 475 $comment_type = $this->get_tag( $comment, 'wp:comment_type'); 476 476 $comment_parent = $this->get_tag( $comment, 'wp:comment_parent'); 477 477 478 if ( !comment_exists($comment_author, $comment_date) ) { 479 $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'); 480 wp_insert_comment($commentdata); 481 $num_comments++; 482 } 478 $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'); 479 wp_insert_comment($commentdata); 480 $num_comments++; 483 481 } } 484 482 485 483 if ( $num_comments ) … … 648 646 return apply_filters('import_attachment_size_limit', 0); 649 647 } 650 648 649 function import_start() { 650 wp_defer_term_counting(true); 651 wp_defer_comment_counting(true); 652 do_action('import_start'); 653 } 654 655 function import_end() { 656 do_action('import_end'); 657 658 // clear the caches after backfilling 659 foreach ($this->post_ids_processed as $post_id) 660 clean_post_cache($post_id); 661 662 wp_defer_term_counting(false); 663 wp_defer_comment_counting(false); 664 } 651 665 652 666 function import($id, $fetch_attachments = false) { 653 667 $this->id = (int) $id; 654 668 $this->fetch_attachments = ($this->allow_fetch_attachments() && (bool) $fetch_attachments); 655 669 656 670 add_filter('import_post_meta_key', array($this, 'is_valid_meta_key')); 657 do_action('import_start');658 671 $file = get_attached_file($this->id); 659 672 $this->import_file($file); 660 do_action('import_end');661 673 } 662 674 663 675 function import_file($file) { 664 676 $this->file = $file; 665 677 678 $this->import_start(); 666 679 $this->get_authors_from_post(); 667 wp_defer_term_counting(true);668 680 $this->get_entries(); 669 681 $this->process_categories(); 670 682 $this->process_tags(); 671 683 $result = $this->process_posts(); 672 684 $this->backfill_parents(); 673 685 $this->backfill_attachment_urls(); 686 $this->import_end(); 674 687 675 // clear the caches after backfilling676 foreach ($this->post_ids_processed as $post_id)677 clean_post_cache($post_id);678 679 wp_defer_term_counting(false);680 688 if ( is_wp_error( $result ) ) 681 689 return $result; 682 690 }