Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Performance improvement for Magento Patch SUPEE-6788
Index: app/code/core/Mage/Admin/Model/Variable.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- app/code/core/Mage/Admin/Model/Variable.php (revision 2bd128c1f190cd9ea63269824f09789199565251)
+++ app/code/core/Mage/Admin/Model/Variable.php (revision )
@@ -30,6 +30,13 @@
class Mage_Admin_Model_Variable extends Mage_Core_Model_Abstract
{
/**
+ * List of loaded variables
+ *
+ * @var array
+ */
+ static protected $_variables = array();
+
+ /**
* Initialize variable model
*/
protected function _construct()
@@ -71,10 +78,12 @@
*/
public function isPathAllowed($path)
{
- /** @var Mage_Admin_Model_Resource_Variable_Collection $collection */
- $collection = Mage::getResourceModel('admin/variable_collection');
- $collection->addFieldToFilter('variable_name', array('eq' => $path))
- ->addFieldToFilter('is_allowed', array('eq' => 1));
- return $collection->load()->count();
+ if (array_key_exists($path, self::$_variables)) {
+ return self::$_variables[$path];
+ }
+ $result = $this->_getResource()->isPathAllowed($path);
+ self::$_variables[$path] = $result;
+
+ return $result;
}
}
Index: app/code/core/Mage/Admin/Model/Resource/Variable.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- app/code/core/Mage/Admin/Model/Resource/Variable.php (revision 2bd128c1f190cd9ea63269824f09789199565251)
+++ app/code/core/Mage/Admin/Model/Resource/Variable.php (revision )
@@ -40,4 +40,24 @@
{
$this->_init('admin/permission_variable', 'variable_id');
}
+
+ /**
+ * Check is config directive with given path can be parsed via configDirective method
+ *
+ * @param string $path
+ * @return int
+ */
+ public function isPathAllowed($path)
+ {
+ $adapter = $this->_getReadAdapter();
+ $select = $adapter->select()
+ ->from($this->getMainTable(), 'COUNT(1)')
+ ->where('variable_name = :variable')
+ ->where('is_allowed = 1');
+ $bind = array(
+ ':variable' => $path,
+ );
+
+ return $adapter->fetchOne($select, $bind);
+ }
}
@dakira

This comment has been minimized.

Copy link

@dakira dakira commented Nov 18, 2015

This should actually make it into an official update.

@capt-tagon

This comment has been minimized.

Copy link

@capt-tagon capt-tagon commented Jan 27, 2016

The 1.9.2.3 Magento upgrade includes a helper which breaks application of this patch and will require changes if still needed.

@AnuragKhandelwal15

This comment has been minimized.

Copy link

@AnuragKhandelwal15 AnuragKhandelwal15 commented Feb 1, 2016

@capt-tagon: Can you give any relevant proof, I just wanted to know so that I can track it as well!

@colinmollenhour

This comment has been minimized.

Copy link

@colinmollenhour colinmollenhour commented Feb 3, 2016

Thanks Dima!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment