[wp-trac] [WordPress Trac] #26530: Unnecessary database requests and untidy code in do_enclose

WordPress Trac noreply at wordpress.org
Wed Dec 11 02:05:39 UTC 2013


#26530: Unnecessary database requests and untidy code in do_enclose
-------------------------+-----------------------------
 Reporter:  joakimf      |      Owner:
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  General      |    Version:  trunk
 Severity:  normal       |   Keywords:
-------------------------+-----------------------------
 The function do_enclose in wp_includes/functions.php is 62 lines long with
 up to 8 levels of intendation, and begins with the comment

 {{{
 //TODO: Tidy this ghetto code up and make the debug code optional
 }}}

 The single biggest problem of this code might be that it unnecessarily
 asks the database if links are referenced as enclosures or not for the
 current post, once for every new link.


 {{{
         foreach ( (array) $post_links as $url ) {
                 if ( $url != '' && !$wpdb->get_var( $wpdb->prepare(
 "SELECT post_id FROM $wpdb->postmeta WHERE post_id = %d AND meta_key =
 'enclosure' AND meta_value LIKE (%s)", $post_ID, like_escape( $url ) . '%'
 ) ) ) {

 }}}

 This information is already available through $pung,


 {{{
         $pung = get_enclosed( $post_ID );

 }}}

 do_enclose also always uses extension guessing to determine the mime type
 of a link, even when there is header information available.

 Bad naming of variables and bad separation of tasks makes the workings
 this function difficult to grasp.

--
Ticket URL: <http://core.trac.wordpress.org/ticket/26530>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list