WordPress.org

Make WordPress Core

Opened 6 years ago

Closed 5 years ago

#7207 closed defect (bug) (invalid)

Optimizations for atom_enclosures and rss_enclosures

Reported by: jacobsantos Owned by: jacobsantos
Milestone: Priority: low
Severity: minor Version: 2.5.1
Component: Optimization Keywords:
Focuses: Cc:

Description

    $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");
        }
    }

Might be faster than

    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");
            }
        }
    }

I'll create a patch later, my repository is dirty at the moment.

Change History (5)

comment:1 DD326 years ago

any reason

if( $encs = get_post_meta($post_id, 'enclosure') ) {
foreach()
}

cant be used? It seems just pulling the particular meta might be faster..

comment:2 jacobsantos6 years ago

I believe the reason get_post_custom() is that it already uses the global ID for the Loop. Using either one will be the same speed, but using your method, DD32, will use less memory as all of the metadata will need to be copied to the $metadata variable, whereas only the metadata that is needed is copied to $encs.

It is almost a moot point, since both functions pull from the metadata cache will get all of the metadata. The copy made in the function will be destroyed when the functions go out of scope however, so in the long run using get_post_meta() will be more memory efficient.

comment:3 matt6 years ago

  • Milestone changed from 2.7 to 2.9

comment:4 jacobsantos6 years ago

  • Owner changed from anonymous to jacobsantos

comment:5 Denis-de-Bernardy5 years ago

  • Milestone 2.9 deleted
  • Resolution set to invalid
  • Status changed from new to closed

code is no longer around

Note: See TracTickets for help on using tickets.