Make WordPress Core


Ignore:
Timestamp:
01/01/2008 05:03:52 PM (17 years ago)
Author:
ryan
Message:

Defer comment counting. Props tellyworth. fixes #5557

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/import/wordpress.php

    r6477 r6532  
    377377        }
    378378
    379         if ($post_id = post_exists($post_title, '', $post_date)) {
     379        $post_exists = post_exists($post_title, '', $post_date);
     380       
     381        if ( $post_exists ) {
    380382            echo '<li>';
    381383            printf(__('Post <i>%s</i> already exists.'), stripslashes($post_title));
     
    476478            $comment_parent       = $this->get_tag( $comment, 'wp:comment_parent');
    477479
    478             if ( !comment_exists($comment_author, $comment_date) ) {
     480            // if this is a new post we can skip the comment_exists() check
     481            if ( !$post_exists || !comment_exists($comment_author, $comment_date) ) {
    479482                $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');
    480483                wp_insert_comment($commentdata);
     
    649652    }
    650653   
     654    function import_start() {
     655        wp_defer_term_counting(true);
     656        wp_defer_comment_counting(true);
     657        do_action('import_start');
     658    }
     659   
     660    function import_end() {
     661        do_action('import_end');
     662       
     663        // clear the caches after backfilling
     664        foreach ($this->post_ids_processed as $post_id)
     665            clean_post_cache($post_id);
     666       
     667        wp_defer_term_counting(false);
     668        wp_defer_comment_counting(false);
     669    }
    651670
    652671    function import($id, $fetch_attachments = false) {
     
    655674
    656675        add_filter('import_post_meta_key', array($this, 'is_valid_meta_key'));
    657         do_action('import_start');
    658676        $file = get_attached_file($this->id);
    659677        $this->import_file($file);
    660         do_action('import_end');
    661678    }
    662679       
     
    664681        $this->file = $file;
    665682       
     683        $this->import_start();
    666684        $this->get_authors_from_post();
    667         wp_defer_term_counting(true);
    668685        $this->get_entries();
    669686        $this->process_categories();
     
    672689        $this->backfill_parents();
    673690        $this->backfill_attachment_urls();
    674        
    675         // clear the caches after backfilling
    676         foreach ($this->post_ids_processed as $post_id)
    677             clean_post_cache($post_id);
    678        
    679         wp_defer_term_counting(false);
     691        $this->import_end();
     692       
    680693        if ( is_wp_error( $result ) )
    681694            return $result;
Note: See TracChangeset for help on using the changeset viewer.