WordPress.org

Make WordPress Core

Changeset 12655


Ignore:
Timestamp:
01/08/2010 05:23:22 AM (11 years ago)
Author:
azaozz
Message:

Optimize scan for lost attachments, props johnjosephbachir, fixes #10911

File:
1 edited

Legend:

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

    r12616 r12655  
    2121        wp_die( __('You are not allowed to scan for lost attachments.') );
    2222
    23     $all_posts = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE post_type = 'post' OR post_type = 'page'");
    24     $all_att = $wpdb->get_results("SELECT ID, post_parent FROM $wpdb->posts WHERE post_type = 'attachment'");
    25 
    26     $lost = array();
    27     foreach ( (array) $all_att as $att ) {
    28         if ( $att->post_parent > 0 && ! in_array($att->post_parent, $all_posts) )
    29             $lost[] = $att->ID;
    30     }
     23    $all_posts = implode(',', $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE post_type IN ('post', 'page')"));
     24    $lost = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE post_type = 'attachment' AND post_parent > '0' and post_parent NOT IN ($all_posts)");
     25
    3126    $_GET['detached'] = 1;
    3227
Note: See TracChangeset for help on using the changeset viewer.