Skip to content

Commit

Permalink
[perf-OpenMage#984] Thumbnails should only get generated once for wys…
Browse files Browse the repository at this point in the history
…iwyg editor
  • Loading branch information
sreichel authored and edannenberg committed Aug 20, 2020
1 parent cab0179 commit e1b0b6a
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions app/code/core/Mage/Cms/Model/Wysiwyg/Images/Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ public function getFilesCollection($path, $type = null)
$item->setUrl($helper->getCurrentUrl() . $item->getBasename());

if ($this->isImage($item->getBasename())) {
$thumbUrl = $this->getThumbnailUrl(
Mage_Core_Model_File_Uploader::getCorrectFileName($item->getFilename()),
true);
$thumbImg = Mage_Core_Model_File_Uploader::getCorrectFileName($item->getBasename());
$thumbUrl = $this->getThumbnailUrl($path . DS . $thumbImg, true);

// generate thumbnail "on the fly" if it does not exists
if(! $thumbUrl) {
$thumbUrl = Mage::getSingleton('adminhtml/url')->getUrl('*/*/thumbnail', array('file' => $item->getId()));
Expand Down Expand Up @@ -340,24 +340,20 @@ public function getThumbnailPath($filePath, $checkFile = false)
*
* @param string $filePath original file path
* @param boolean $checkFile OPTIONAL is it necessary to check file availability
* @return string | false
* @return string|false
*/
public function getThumbnailUrl($filePath, $checkFile = false)
{
$mediaRootDir = Mage::getConfig()->getOptions()->getMediaDir() . DS;

if (strpos($filePath, $mediaRootDir) === 0) {
$thumbSuffix = self::THUMBS_DIRECTORY_NAME . DS . Mage_Cms_Model_Wysiwyg_Config::IMAGE_DIRECTORY
. DS . substr($filePath, strlen($mediaRootDir));

if (! $checkFile || is_readable($this->getHelper()->getStorageRoot() . $thumbSuffix)) {
$thumbSuffix = self::THUMBS_DIRECTORY_NAME . DS . substr($filePath, strlen($mediaRootDir));
if (!$checkFile || is_readable($this->getHelper()->getStorageRoot() . $thumbSuffix)) {
$randomIndex = '?rand=' . time();
$thumbUrl = $this->getHelper()->getBaseUrl() . Mage_Cms_Model_Wysiwyg_Config::IMAGE_DIRECTORY
. DS . $thumbSuffix;
return str_replace('\\', '/', $thumbUrl) . $randomIndex;
}
}

return false;
}

Expand Down

0 comments on commit e1b0b6a

Please sign in to comment.