Skip to content

Instantly share code, notes, and snippets.

@DimaSoroka
Last active January 11, 2019 21:48
Show Gist options
  • Save DimaSoroka/a3e567ddc39bd6a39c4e to your computer and use it in GitHub Desktop.
Save DimaSoroka/a3e567ddc39bd6a39c4e to your computer and use it in GitHub Desktop.
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);
+ }
}
@capt-tagon
Copy link

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

@AnuragKhandelwal15
Copy link

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

@colinmollenhour
Copy link

Thanks Dima!

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