Opened 16 years ago
Closed 15 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)
#2
@
16 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.
Note: See
TracTickets for help on using
tickets.
any reason
cant be used? It seems just pulling the particular meta might be faster..