Defer term counting during import. Props tellyworth. fixes #5377
git-svn-id: http://svn.automattic.com/wordpress/trunk@6376 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
0f846cd38f
commit
805e41198c
|
@ -446,11 +446,13 @@ class WP_Import {
|
|||
$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();
|
||||
wp_defer_term_counting(false);
|
||||
if ( is_wp_error( $result ) )
|
||||
return $result;
|
||||
}
|
||||
|
|
|
@ -1317,6 +1317,21 @@ function wp_update_term( $term, $taxonomy, $args = array() ) {
|
|||
return array('term_id' => $term_id, 'term_taxonomy_id' => $tt_id);
|
||||
}
|
||||
|
||||
// enable or disable term count deferring
|
||||
// if no value is supplied, the current value of the defer setting is returned
|
||||
function wp_defer_term_counting($defer=NULL) {
|
||||
static $_defer = false;
|
||||
|
||||
if ( is_bool($defer) ) {
|
||||
$_defer = $defer;
|
||||
// flush any deferred counts
|
||||
if ( !$defer )
|
||||
wp_update_term_count( NULL, NULL, true );
|
||||
}
|
||||
|
||||
return $_defer;
|
||||
}
|
||||
|
||||
/**
|
||||
* wp_update_term_count() - Updates the amount of terms in taxonomy
|
||||
*
|
||||
|
@ -1334,8 +1349,15 @@ function wp_update_term( $term, $taxonomy, $args = array() ) {
|
|||
* @param string $taxonomy The context of the term.
|
||||
* @return bool If no terms will return false, and if successful will return true.
|
||||
*/
|
||||
function wp_update_term_count( $terms, $taxonomy ) {
|
||||
global $wpdb;
|
||||
function wp_update_term_count( $terms, $taxonomy, $do_deferred=false ) {
|
||||
static $_deferred = array();
|
||||
|
||||
if ( $do_deferred ) {
|
||||
foreach ( array_keys($_deferred) as $tax ) {
|
||||
wp_update_term_count_now( $_deferred[$tax], $tax );
|
||||
unset( $_deferred[$tax] );
|
||||
}
|
||||
}
|
||||
|
||||
if ( empty($terms) )
|
||||
return false;
|
||||
|
@ -1343,6 +1365,19 @@ function wp_update_term_count( $terms, $taxonomy ) {
|
|||
if ( !is_array($terms) )
|
||||
$terms = array($terms);
|
||||
|
||||
if ( wp_defer_term_counting() ) {
|
||||
if ( !isset($_deferred[$taxonomy]) )
|
||||
$_deferred[$taxonomy] = array();
|
||||
$_deferred[$taxonomy] = array_unique( array_merge($_deferred[$taxonomy], $terms) );
|
||||
return true;
|
||||
}
|
||||
|
||||
return wp_update_term_count_now( $terms, $taxonomy );
|
||||
}
|
||||
|
||||
function wp_update_term_count_now( $terms, $taxonomy ) {
|
||||
global $wpdb;
|
||||
|
||||
$terms = array_map('intval', $terms);
|
||||
|
||||
$taxonomy = get_taxonomy($taxonomy);
|
||||
|
|
Loading…
Reference in New Issue