WordPress.org

Make WordPress Core

Changeset 5785


Ignore:
Timestamp:
07/06/2007 08:57:28 PM (11 years ago)
Author:
ryan
Message:

Reduce export mem usage. Props tellyworth. fixes #4589

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/export.php

    r5711 r5785  
    4646
    4747function export_wp() {
    48 global $wpdb, $posts, $post;
     48global $wpdb, $post_ids, $post;
    4949
    5050$filename = 'wordpress.' . date('Y-m-d') . '.xml';
     
    6060}
    6161
    62 $posts = $wpdb->get_results("SELECT * FROM $wpdb->posts $where ORDER BY post_date_gmt ASC");
     62// grab a snapshot of post IDs, just in case it changes during the export
     63$post_ids = $wpdb->get_col("SELECT ID FROM $wpdb->posts $where ORDER BY post_date_gmt ASC");
    6364
    6465$categories = (array) get_categories('get=all');
     
    167168<?php endforeach; endif; ?>
    168169    <?php do_action('rss2_head'); ?>
    169     <?php if ($posts) { foreach ($posts as $post) { start_wp(); ?>
     170    <?php if ($post_ids) {
     171        // fetch 20 posts at a time rather than loading the entire table into memory
     172        while ( $next_posts = array_splice($post_ids, 0, 20) ) {
     173            $where = "WHERE ID IN (".join(',', $next_posts).")";
     174            $posts = $wpdb->get_results("SELECT * FROM $wpdb->posts $where ORDER BY post_date_gmt ASC");
     175                foreach ($posts as $post) {
     176            start_wp(); ?>
    170177<item>
    171178<title><?php the_title_rss() ?></title>
     
    217224<?php } } ?>
    218225    </item>
    219 <?php } } ?>
     226<?php } } } ?>
    220227</channel>
    221228</rss>
Note: See TracChangeset for help on using the changeset viewer.