Skip to content

Commit 7267335

Browse files
committed
Cache Elasticsearch field mappers per entity
1 parent 6e534ad commit 7267335

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

app/code/Magento/Elasticsearch/Model/Adapter/FieldMapper/FieldMapperResolver.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ class FieldMapperResolver implements FieldMapperInterface
2424
private $fieldMappers;
2525

2626
/**
27-
* Field Mapper instance
27+
* Field Mapper instance per entity
2828
*
29-
* @var FieldMapperInterface
29+
* @var FieldMapperInterface[]
3030
*/
31-
private $fieldMapperEntity;
31+
private $fieldMapperEntity = [];
3232

3333
/**
3434
* @param ObjectManagerInterface $objectManager
@@ -69,7 +69,7 @@ public function getAllAttributesTypes($context = [])
6969
*/
7070
private function getEntity($entityType)
7171
{
72-
if (empty($this->fieldMapperEntity)) {
72+
if (empty($this->fieldMapperEntity[$entityType])) {
7373
if (empty($entityType)) {
7474
throw new \Exception(
7575
'No entity type given'
@@ -81,13 +81,13 @@ private function getEntity($entityType)
8181
);
8282
}
8383
$fieldMapperClass = $this->fieldMappers[$entityType];
84-
$this->fieldMapperEntity = $this->objectManager->create($fieldMapperClass);
85-
if (!($this->fieldMapperEntity instanceof FieldMapperInterface)) {
84+
$this->fieldMapperEntity[$entityType] = $this->objectManager->create($fieldMapperClass);
85+
if (!($this->fieldMapperEntity[$entityType] instanceof FieldMapperInterface)) {
8686
throw new \InvalidArgumentException(
8787
'Field mapper must implement \Magento\Elasticsearch\Model\Adapter\FieldMapperInterface'
8888
);
8989
}
9090
}
91-
return $this->fieldMapperEntity;
91+
return $this->fieldMapperEntity[$entityType];
9292
}
9393
}

0 commit comments

Comments
 (0)