[wp-hackers] Possible optimizations to rss_enclosures and
	atom_enclosures
    Jacob Santos 
    wordpress at santosj.name
       
    Sun Jun 29 06:20:05 GMT 2008
    
    
  
Before I create a ticket I want to confirm that there isn't something 
I'm missing with the code. I'm not sure if this is intentional and there 
is something that I'm missing. However, with what I know, it seems like 
it can be improved.
{{{
foreach (get_post_custom() as $key => $val) {
        if ($key == 'enclosure') {
            foreach ((array)$val as $enc) {
                $enclosure = split("\n", $enc);
                echo apply_filters('atom_enclosure', '<link href="' . 
trim(htmlspecialchars($enclosure[0])) . '" rel="enclosure" length="' . 
trim($enclosure[1]) . '" type="' . trim($enclosure[2]) . '" />' . "\n");
            }
        }
    }
}}}
Can be reduced to
{{{
$metadata = get_post_custom();
    if( isset($metadata['enclosure']) ) {
        foreach( (array) $metadata['enclosure'] as $enc ) {
            $enclosure = split("\n", $enc);
            echo apply_filters('atom_enclosure', '<link href="' . 
trim(htmlspecialchars($enclosure[0])) . '" rel="enclosure" length="' . 
trim($enclosure[1]) . '" type="' . trim($enclosure[2]) . '" />' . "\n");
        }
    }
}}}
or even:
{{{
$metadata = get_post_custom();
foreach( (array) $metadata['enclosure'] as $enc ) {
    $enclosure = split("\n", $enc);
    echo apply_filters('atom_enclosure', '<link href="' . 
trim(htmlspecialchars($enclosure[0])) . '" rel="enclosure" length="' . 
trim($enclosure[1]) . '" type="' . trim($enclosure[2]) . '" />' . "\n");
}
}}}
Depending on the amount of the post metadata, looping through all of the 
metadata when it is not needed doesn't seem efficient and could become 
very slow on systems which have posts with a lot of metadata.
Both rss_enclosures and atom_enclosures are this way.
Jacob Santos
    
    
More information about the wp-hackers
mailing list