@@ -89,9 +89,9 @@ abstract class AbstractDb extends \Magento\Framework\Data\Collection
89
89
/**
90
90
* Flag which determines if extension attributes were joined before the collection was loaded.
91
91
*
92
- * @var bool
92
+ * @var callable|null
93
93
*/
94
- private $ extensionAttributesJoined = false ;
94
+ protected $ extensionAttributesExtractorCallback ;
95
95
96
96
/**
97
97
* @param EntityFactoryInterface $entityFactory
@@ -743,6 +743,7 @@ protected function _reset()
743
743
$ this ->_setIsLoaded (false );
744
744
$ this ->_items = [];
745
745
$ this ->_data = null ;
746
+ $ this ->extensionAttributesExtractorCallback = null ;
746
747
return $ this ;
747
748
}
748
749
@@ -755,15 +756,11 @@ protected function _reset()
755
756
protected function _fetchAll (\Zend_Db_Select $ select )
756
757
{
757
758
$ data = $ this ->_fetchStrategy ->fetchAll ($ select , $ this ->_bindParams );
758
- if ($ this ->extensionAttributesJoined ) {
759
- // TODO: Temporary implementation to evaluate performance improvement
760
- /** @var \Magento\Framework\Api\ExtensionAttributesFactory $extensionAttributesFactory */
761
- $ extensionAttributesFactory = \Magento \Framework \App \ObjectManager::getInstance ()
762
- ->get ('Magento\Framework\Api\ExtensionAttributesFactory ' );
759
+ if ($ this ->extensionAttributesExtractorCallback && is_callable ($ this ->extensionAttributesExtractorCallback )) {
763
760
foreach ($ data as $ key => $ dataItem ) {
764
- $ data [$ key ] = $ extensionAttributesFactory -> extractExtensionAttributes (
765
- $ this ->_itemObjectClass ,
766
- $ dataItem
761
+ $ data [$ key ] = call_user_func_array (
762
+ $ this ->extensionAttributesExtractorCallback ,
763
+ [ $ this -> _itemObjectClass , $ dataItem]
767
764
);
768
765
}
769
766
}
@@ -816,9 +813,10 @@ protected function _initSelect()
816
813
* Join extension attribute.
817
814
*
818
815
* @param \Magento\Framework\Api\ExtensionAttribute\JoinData $join
816
+ * @param callable $extensionAttributesExtractorCallback
819
817
* @return $this
820
818
*/
821
- public function joinExtensionAttribute ($ join )
819
+ public function joinExtensionAttribute ($ join, $ extensionAttributesExtractorCallback )
822
820
{
823
821
$ selectFrom = $ this ->getSelect ()->getPart (\Zend_Db_Select::FROM );
824
822
$ joinRequired = !isset ($ selectFrom [$ join ->getReferenceTableAlias ()]);
@@ -836,7 +834,7 @@ public function joinExtensionAttribute($join)
836
834
$ columns [$ fieldAlias ] = $ join ->getReferenceTableAlias () . '. ' . $ selectField ;
837
835
}
838
836
$ this ->getSelect ()->columns ($ columns );
839
- $ this ->extensionAttributesJoined = ! empty ( $ columns ) ?: false ;
837
+ $ this ->extensionAttributesExtractorCallback = $ extensionAttributesExtractorCallback ;
840
838
return $ this ;
841
839
}
842
840
0 commit comments