Skip to content
Snippets Groups Projects
Commit ca14c6f6 authored by Alex Barth's avatar Alex Barth
Browse files

Push static caching for mapping targets into map().

parent dacc63c0
No related branches found
No related tags found
No related merge requests found
...@@ -226,34 +226,33 @@ class FeedsNodeProcessor extends FeedsProcessor { ...@@ -226,34 +226,33 @@ class FeedsNodeProcessor extends FeedsProcessor {
* Static cached, may be called multiple times in a page load. * Static cached, may be called multiple times in a page load.
*/ */
public function getMappingTargets() { public function getMappingTargets() {
static $targets; $targets = array(
if (empty($targets)) { 'title' => array(
$targets = array( 'name' => t('Title'),
'title' => array( ),
'name' => t('Title'), 'status' => array(
), 'name' => t('Published status'),
'status' => array( ),
'name' => t('Published status'), 'created' => array(
), 'name' => t('Published date'),
'created' => array( ),
'name' => t('Published date'), // Using 'teaser' instead of 'body' forces entire content above the break.
), 'body' => array(
// Using 'teaser' instead of 'body' forces entire content above the break. 'name' => t('Body'),
'body' => array( ),
'name' => t('Body'), 'url' => array(
), 'name' => t('URL'),
'url' => array( 'optional_unique' => TRUE,
'name' => t('URL'), ),
'optional_unique' => TRUE, 'guid' => array(
), 'name' => t('GUID'),
'guid' => array( 'optional_unique' => TRUE,
'name' => t('GUID'), ),
'optional_unique' => TRUE, );
),
); self::loadMappers();
self::loadMappers(); drupal_alter('feeds_node_processor_targets', $targets, $this->config['content_type']);
drupal_alter('feeds_node_processor_targets', $targets, $this->config['content_type']);
}
return $targets; return $targets;
} }
......
...@@ -51,6 +51,12 @@ abstract class FeedsProcessor extends FeedsPlugin { ...@@ -51,6 +51,12 @@ abstract class FeedsProcessor extends FeedsPlugin {
* Execute mapping on an item. * Execute mapping on an item.
*/ */
protected function map($source_item, $target_item = NULL) { protected function map($source_item, $target_item = NULL) {
// Static cache $targets as getMappingTargets() may be an expensive method.
static $targets;
if (empty($targets)) {
$targets = $this->getMappingTargets();
}
$parser = feeds_importer($this->id)->parser; $parser = feeds_importer($this->id)->parser;
if (empty($target_item)) { if (empty($target_item)) {
$target_item = array(); $target_item = array();
...@@ -65,7 +71,6 @@ abstract class FeedsProcessor extends FeedsPlugin { ...@@ -65,7 +71,6 @@ abstract class FeedsProcessor extends FeedsPlugin {
If the mapping specifies a callback method, use the callback instead of If the mapping specifies a callback method, use the callback instead of
setTargetElement(). setTargetElement().
*/ */
$targets = $this->getMappingTargets();
foreach ($this->config['mappings'] as $mapping) { foreach ($this->config['mappings'] as $mapping) {
$value = $parser->getSourceElement($source_item, $mapping['source']); $value = $parser->getSourceElement($source_item, $mapping['source']);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment