-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Commit the Sitewards ImportImageMemoryLeakFix for publishing to GitHub
- Loading branch information
David Manners
committed
May 10, 2016
0 parents
commit e849bd3
Showing
7 changed files
with
129 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
Sitewards ImportImageMemoryLeakFix | ||
================================== | ||
|
||
Issue | ||
----- | ||
|
||
Product import with images easily goes over 4Gb on memory with just couple hundreds of products. | ||
The reason for this is that the image model is never properly destoried. | ||
|
||
Fix | ||
--- | ||
|
||
Use a different image processor than `Varien_Image`. | ||
Add a `destruct` method into this new processor and register it on shutdown. | ||
Rewrite `Mage_Catalog_Helper_Image` to change the method `validateUploadFile`. | ||
Call new processor, call destruct and then return the mime type of the image. |
33 changes: 33 additions & 0 deletions
33
app/code/local/Sitewards/ImportImageMemoryLeakFix/Helper/Catalog/Helper/Image.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
/** | ||
* @category Sitewards | ||
* @package Sitewards_ImportImageMemoryLeakFix | ||
* @copyright Copyright (c) Sitewards GmbH (http://www.sitewards.com/) | ||
*/ | ||
class Sitewards_ImportImageMemoryLeakFix_Helper_Catalog_Helper_Image extends Mage_Catalog_Helper_Image | ||
{ | ||
/** | ||
* Check - is this file an image | ||
* | ||
* Difference from original method - we destroy the image object here, | ||
* i.e. we are not wasting memory, without that fix product import with images | ||
* easily goes over 4Gb on memory with just couple hundreds of products. | ||
* | ||
* @param string $sFilePath | ||
* | ||
* @return bool | ||
* @throws Mage_Core_Exception | ||
*/ | ||
public function validateUploadFile($sFilePath) { | ||
if (!getimagesize($sFilePath)) { | ||
Mage::throwException($this->__('Disallowed file type.')); | ||
} | ||
|
||
/** @var Sitewards_ImportImageMemoryLeakFix_Model_Destructable_Image $oImageProcessor */ | ||
$oImageProcessor = Mage::getModel('sitewards_importimagememoryleakfix/destructable_image', $sFilePath); | ||
$sMimeType = $oImageProcessor->getMimeType(); | ||
$oImageProcessor->destruct(); | ||
|
||
return $sMimeType !== null; | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
app/code/local/Sitewards/ImportImageMemoryLeakFix/Model/Destructable/Image.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
/** | ||
* @category Sitewards | ||
* @package Sitewards_ImportImageMemoryLeakFix | ||
* @copyright Copyright (c) Sitewards GmbH (http://www.sitewards.com/) | ||
*/ | ||
class Sitewards_ImportImageMemoryLeakFix_Model_Destructable_Image extends Varien_Image | ||
{ | ||
/** | ||
* Constructor, | ||
* difference from original constructor - we register a destructor here. | ||
* | ||
* @param string $sFileName | ||
* @param Varien_Image_Adapter $oAdapter Default value is GD2 | ||
*/ | ||
public function __construct($sFileName = null, $oAdapter = Varien_Image_Adapter::ADAPTER_GD2) | ||
{ | ||
parent::__construct($sFileName, $oAdapter); | ||
|
||
// Initialize shutdown function | ||
register_shutdown_function(array($this, 'destruct')); | ||
} | ||
|
||
/** | ||
* Destroy object image on shutdown | ||
*/ | ||
public function destruct() | ||
{ | ||
$oAdapter = $this->_getAdapter(); | ||
if (method_exists($oAdapter, 'destruct')) { | ||
$oAdapter->destruct(); | ||
} else { | ||
Mage::log('Image can not be destructed properly, adapter doesn\'t support the method.'); | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
app/code/local/Sitewards/ImportImageMemoryLeakFix/etc/config.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?xml version="1.0"?> | ||
<config> | ||
<modules> | ||
<Sitewards_ImportImageMemoryLeakFix> | ||
<version>0.1.0</version> | ||
</Sitewards_ImportImageMemoryLeakFix> | ||
</modules> | ||
<global> | ||
<models> | ||
<sitewards_importimagememoryleakfix> | ||
<class>Sitewards_ImportImageMemoryLeakFix_Model</class> | ||
</sitewards_importimagememoryleakfix> | ||
</models> | ||
<helpers> | ||
<catalog> | ||
<rewrite> | ||
<image>Sitewards_ImportImageMemoryLeakFix_Helper_Catalog_Helper_Image</image> | ||
</rewrite> | ||
</catalog> | ||
</helpers> | ||
</global> | ||
</config> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0"?> | ||
<config> | ||
<modules> | ||
<Sitewards_ImportImageMemoryLeakFix> | ||
<active>true</active> | ||
<codePool>local</codePool> | ||
<depends> | ||
<Mage_Catalog/> | ||
</depends> | ||
</Sitewards_ImportImageMemoryLeakFix> | ||
</modules> | ||
</config> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"name": "sitewards/import_image_memory_leak_fix", | ||
"description": "Fix a memory leak issue with the product image import process.", | ||
"type": "magento-module", | ||
"require": { | ||
"php": ">=5.5" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
app/code/local/Sitewards/ImportImageMemoryLeakFix app/code/local/Sitewards/ImportImageMemoryLeakFix | ||
app/etc/modules/Sitewards_ImportImageMemoryLeakFix.xml app/etc/modules/Sitewards_ImportImageMemoryLeakFix |