Skip to content

Commit

Permalink
Merge pull request #2077 from magento-performance/perf_pr_2.3
Browse files Browse the repository at this point in the history
[performance] MAGETWO-87609: Add cache for getimagesize() function for product images
  • Loading branch information
vzabaznov authored Feb 13, 2018
2 parents fa906ed + 6eb7e35 commit a86fd3f
Show file tree
Hide file tree
Showing 43 changed files with 10,268 additions and 8,936 deletions.
62 changes: 46 additions & 16 deletions app/code/Magento/Bundle/Model/ResourceModel/Option.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,31 +81,39 @@ protected function _afterSave(\Magento\Framework\Model\AbstractModel $object)
{
parent::_afterSave($object);

$condition = [
$conditions = [
'option_id = ?' => $object->getId(),
'store_id = ? OR store_id = 0' => $object->getStoreId(),
'parent_product_id = ?' => $object->getParentId()
];

$connection = $this->getConnection();
$connection->delete($this->getTable('catalog_product_bundle_option_value'), $condition);

$data = new \Magento\Framework\DataObject();
$data->setOptionId($object->getId())
->setStoreId($object->getStoreId())
->setParentProductId($object->getParentId())
->setTitle($object->getTitle());

$connection->insert($this->getTable('catalog_product_bundle_option_value'), $data->getData());

/**
* also saving default value if this store view scope
*/
if ($this->isOptionPresent($conditions)) {
$connection->update(
$this->getTable('catalog_product_bundle_option_value'),
[
'title' => $object->getTitle()
],
$conditions
);
} else {
$data = new \Magento\Framework\DataObject();
$data->setOptionId($object->getId())
->setStoreId($object->getStoreId())
->setParentProductId($object->getParentId())
->setTitle($object->getTitle());

if ($object->getStoreId()) {
$data->setStoreId(0);
$data->setTitle($object->getDefaultTitle());
$connection->insert($this->getTable('catalog_product_bundle_option_value'), $data->getData());

/**
* also saving default value if this store view scope
*/
if ($object->getStoreId()) {
$data->setStoreId(0);
$data->setTitle($object->getDefaultTitle());
$connection->insert($this->getTable('catalog_product_bundle_option_value'), $data->getData());
}
}

return $this;
Expand Down Expand Up @@ -210,4 +218,26 @@ public function save(\Magento\Framework\Model\AbstractModel $object)

return $this;
}

/**
* Is Bundle option present in the database
*
* @param array $conditions
*
* @return bool
*/
private function isOptionPresent($conditions)
{
$connection = $this->getConnection();

$select = $connection->select()->from($this->getTable('catalog_product_bundle_option_value'));
foreach ($conditions as $condition => $conditionValue) {
$select->where($condition, $conditionValue);
}
$select->limit(1);

$rowSelect = $connection->fetchRow($select);

return (is_array($rowSelect) && !empty($rowSelect));
}
}
45 changes: 0 additions & 45 deletions app/code/Magento/Catalog/Block/Product/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,51 +120,6 @@ public function getWishlistOptions()
return ['productType' => $this->getProduct()->getTypeId()];
}

/**
* Add meta information from product to head block
*
* @return \Magento\Catalog\Block\Product\View
*/
protected function _prepareLayout()
{
$this->getLayout()->createBlock(\Magento\Catalog\Block\Breadcrumbs::class);
$product = $this->getProduct();
if (!$product) {
return parent::_prepareLayout();
}

$title = $product->getMetaTitle();
if ($title) {
$this->pageConfig->getTitle()->set($title);
}
$keyword = $product->getMetaKeyword();
$currentCategory = $this->_coreRegistry->registry('current_category');
if ($keyword) {
$this->pageConfig->setKeywords($keyword);
} elseif ($currentCategory) {
$this->pageConfig->setKeywords($product->getName());
}
$description = $product->getMetaDescription();
if ($description) {
$this->pageConfig->setDescription($description);
} else {
$this->pageConfig->setDescription($this->string->substr($product->getDescription(), 0, 255));
}
if ($this->_productHelper->canUseCanonicalTag()) {
$this->pageConfig->addRemotePageAsset(
$product->getUrlModel()->getUrl($product, ['_ignore_category' => true]),
'canonical',
['attributes' => ['rel' => 'canonical']]
);
}

$pageMainTitle = $this->getLayout()->getBlock('page.main.title');
if ($pageMainTitle) {
$pageMainTitle->setPageTitle($product->getName());
}
return parent::_prepareLayout();
}

/**
* Retrieve current product model
*
Expand Down
62 changes: 61 additions & 1 deletion app/code/Magento/Catalog/Helper/Product/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ class View extends \Magento\Framework\App\Helper\AbstractHelper
*/
protected $categoryUrlPathGenerator;

/**
* @var \Magento\Framework\Stdlib\StringUtils
*/
private $string;

/**
* Constructor
*
Expand All @@ -70,6 +75,7 @@ class View extends \Magento\Framework\App\Helper\AbstractHelper
* @param \Magento\Framework\Message\ManagerInterface $messageManager
* @param \Magento\CatalogUrlRewrite\Model\CategoryUrlPathGenerator $categoryUrlPathGenerator
* @param array $messageGroups
* @param \Magento\Framework\Stdlib\StringUtils|null $string
*/
public function __construct(
\Magento\Framework\App\Helper\Context $context,
Expand All @@ -79,7 +85,8 @@ public function __construct(
\Magento\Framework\Registry $coreRegistry,
\Magento\Framework\Message\ManagerInterface $messageManager,
\Magento\CatalogUrlRewrite\Model\CategoryUrlPathGenerator $categoryUrlPathGenerator,
array $messageGroups = []
array $messageGroups = [],
\Magento\Framework\Stdlib\StringUtils $string = null
) {
$this->_catalogSession = $catalogSession;
$this->_catalogDesign = $catalogDesign;
Expand All @@ -88,9 +95,61 @@ public function __construct(
$this->messageGroups = $messageGroups;
$this->messageManager = $messageManager;
$this->categoryUrlPathGenerator = $categoryUrlPathGenerator;
$this->string = $string ?: \Magento\Framework\App\ObjectManager::getInstance()
->get(\Magento\Framework\Stdlib\StringUtils::class);
parent::__construct($context);
}

/**
* Add meta information from product to layout
*
* @param \Magento\Framework\View\Result\Page $resultPage
* @param \Magento\Catalog\Model\Product $product
* @return \Magento\Framework\View\Result\Page
*/
private function preparePageMetadata(ResultPage $resultPage, $product)
{
$pageLayout = $resultPage->getLayout();
$pageLayout->createBlock(\Magento\Catalog\Block\Breadcrumbs::class);

$pageConfig = $resultPage->getConfig();

$title = $product->getMetaTitle();
if ($title) {
$pageConfig->getTitle()->set($title);
}

$keyword = $product->getMetaKeyword();
$currentCategory = $this->_coreRegistry->registry('current_category');
if ($keyword) {
$pageConfig->setKeywords($keyword);
} elseif ($currentCategory) {
$pageConfig->setKeywords($product->getName());
}

$description = $product->getMetaDescription();
if ($description) {
$pageConfig->setDescription($description);
} else {
$pageConfig->setDescription($this->string->substr($product->getDescription(), 0, 255));
}

if ($this->_catalogProduct->canUseCanonicalTag()) {
$pageConfig->addRemotePageAsset(
$product->getUrlModel()->getUrl($product, ['_ignore_category' => true]),
'canonical',
['attributes' => ['rel' => 'canonical']]
);
}

$pageMainTitle = $pageLayout->getBlock('page.main.title');
if ($pageMainTitle) {
$pageMainTitle->setPageTitle($product->getName());
}

return $this;
}

/**
* Init layout for viewing product page
*
Expand Down Expand Up @@ -225,6 +284,7 @@ public function prepareAndRender(ResultPage $resultPage, $productId, $controller
}

$this->initProductLayout($resultPage, $product, $params);
$this->preparePageMetadata($resultPage, $product);
return $this;
}
}
13 changes: 7 additions & 6 deletions app/code/Magento/Catalog/Model/Product/Gallery/CreateHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,13 @@ protected function processNewAndExistingImages($product, array &$images)
if (empty($image['removed'])) {
$data = $this->processNewImage($product, $image);

$this->resourceModel->deleteGalleryValueInStore(
$image['value_id'],
$product->getData($this->metadata->getLinkField()),
$product->getStoreId()
);

if (!$product->isObjectNew()) {
$this->resourceModel->deleteGalleryValueInStore(
$image['value_id'],
$product->getData($this->metadata->getLinkField()),
$product->getStoreId()
);
}
// Add per store labels, position, disabled
$data['value_id'] = $image['value_id'];
$data['label'] = isset($image['label']) ? $image['label'] : '';
Expand Down
Loading

0 comments on commit a86fd3f

Please sign in to comment.