diff --git a/app/code/Magento/Eav/Model/Config.php b/app/code/Magento/Eav/Model/Config.php index 832966d134776..760c1b88b844a 100644 --- a/app/code/Magento/Eav/Model/Config.php +++ b/app/code/Magento/Eav/Model/Config.php @@ -418,7 +418,7 @@ protected function _initAttributes($entityType) * * @param mixed $entityType * @param mixed $code - * @return \Magento\Eav\Model\Entity\Attribute\AbstractAttribute|false + * @return \Magento\Eav\Model\Entity\Attribute\AbstractAttribute * @throws \Magento\Framework\Exception\LocalizedException */ public function getAttribute($entityType, $code) diff --git a/app/design/frontend/Magento/blank/etc/view.xml b/app/design/frontend/Magento/blank/etc/view.xml index 2e036c02197d6..4cb285447a896 100644 --- a/app/design/frontend/Magento/blank/etc/view.xml +++ b/app/design/frontend/Magento/blank/etc/view.xml @@ -286,5 +286,6 @@ Lib::mage/requirejs Lib::mage/adminhtml Lib::mage/backend + Magento_Swagger::swagger-ui diff --git a/app/design/frontend/Magento/luma/etc/view.xml b/app/design/frontend/Magento/luma/etc/view.xml index e4f42fabb5c33..29413b10e9350 100644 --- a/app/design/frontend/Magento/luma/etc/view.xml +++ b/app/design/frontend/Magento/luma/etc/view.xml @@ -290,5 +290,6 @@ Lib::mage/requirejs Lib::mage/adminhtml Lib::mage/backend + Magento_Swagger::swagger-ui diff --git a/lib/internal/Magento/Framework/View/Asset/Bundle.php b/lib/internal/Magento/Framework/View/Asset/Bundle.php index d19d667d61216..4ffbddfb6812d 100644 --- a/lib/internal/Magento/Framework/View/Asset/Bundle.php +++ b/lib/internal/Magento/Framework/View/Asset/Bundle.php @@ -21,6 +21,11 @@ class Bundle */ protected $assets = []; + /** + * @var array + */ + protected $assetsContent = []; + /** @var Bundle\Config */ protected $bundleConfig; @@ -79,10 +84,8 @@ protected function add(LocalInterface $asset) $parts = &$this->assets[$this->getContextCode($asset)][$asset->getContentType()]; if (!isset($parts[$partIndex])) { $parts[$partIndex]['assets'] = []; - $parts[$partIndex]['space'] = $this->getMaxPartSize($asset); } $parts[$partIndex]['assets'][$this->getAssetKey($asset)] = $asset; - $parts[$partIndex]['space'] -= $this->getAssetSize($asset); } /** @@ -119,12 +122,11 @@ protected function getPartIndex(LocalInterface $asset) $parts = $this->assets[$this->getContextCode($asset)][$asset->getContentType()]; $maxPartSize = $this->getMaxPartSize($asset); - $assetSize = $this->getAssetSize($asset); - $minSpace = $maxPartSize + 1; + $minSpace = $maxPartSize; $minIndex = -1; if ($maxPartSize && count($parts)) { foreach ($parts as $partIndex => $part) { - $space = $part['space'] - $assetSize; + $space = $maxPartSize - $this->getSizePartWithNewAsset($asset, $part['assets']); if ($space >= 0 && $space < $minSpace) { $minSpace = $space; $minIndex = $partIndex; @@ -145,12 +147,16 @@ protected function getMaxPartSize(LocalInterface $asset) } /** + * Get part size after adding new asset + * * @param LocalInterface $asset - * @return int + * @param LocalInterface[] $assets + * @return float */ - protected function getAssetSize(LocalInterface $asset) + protected function getSizePartWithNewAsset(LocalInterface $asset, $assets = []) { - return mb_strlen(json_encode(utf8_encode($asset->getContent()), JSON_UNESCAPED_SLASHES), 'utf-8') / 1024; + $assets[$this->getAssetKey($asset)] = $asset; + return mb_strlen($this->getPartContent($assets), 'utf-8') / 1024; } /** @@ -176,7 +182,7 @@ protected function getPartContent($assets) { $contents = []; foreach ($assets as $key => $asset) { - $contents[$key] = utf8_encode($asset->getContent()); + $contents[$key] = $this->getAssetContent($asset); } $partType = reset($assets)->getContentType(); @@ -190,6 +196,24 @@ protected function getPartContent($assets) return $content; } + /** + * Get content of asset + * + * @param LocalInterface $asset + * @return string + */ + protected function getAssetContent(LocalInterface $asset) + { + $assetContextCode = $this->getContextCode($asset); + $assetContentType = $asset->getContentType(); + $assetKey = $this->getAssetKey($asset); + if (!isset($this->assetsContent[$assetContextCode][$assetContentType][$assetKey])) { + $this->assetsContent[$assetContextCode][$assetContentType][$assetKey] = utf8_encode($asset->getContent()); + } + + return $this->assetsContent[$assetContextCode][$assetContentType][$assetKey]; + } + /** * @return string */ @@ -220,6 +244,7 @@ public function flush() } $this->assets = []; $this->content = []; + $this->assetsContent = []; } /** diff --git a/lib/internal/Magento/Framework/View/Test/Unit/Asset/BundleTest.php b/lib/internal/Magento/Framework/View/Test/Unit/Asset/BundleTest.php index d49267b466191..2c838e8bebeb0 100644 --- a/lib/internal/Magento/Framework/View/Test/Unit/Asset/BundleTest.php +++ b/lib/internal/Magento/Framework/View/Test/Unit/Asset/BundleTest.php @@ -66,10 +66,12 @@ public function testMinSuffix() ->expects($this->any()) ->method('addMinifiedSign') ->withConsecutive( + ['onefile.js'], ['onefile.js'], ['/js/bundle/bundle0.js'] ) ->willReturnOnConsecutiveCalls( + 'onefile.min.js', 'onefile.min.js', '/js/bundle/bundle0.min.js' );