Skip to content

Instantly share code, notes, and snippets.

@dng-dev
Created August 2, 2016 10:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dng-dev/4919c7c305cbee2e0f2a9db7655d5198 to your computer and use it in GitHub Desktop.
Save dng-dev/4919c7c305cbee2e0f2a9db7655d5198 to your computer and use it in GitHub Desktop.
this small patch fixes 3 DB queries for the fishpig magento wordpress integration
diff --git a/app/code/community/Fishpig/Wordpress/Helper/Config.php b/app/code/community/Fishpig/Wordpress/Helper/Config.php
index 51f7d7d..742fe6a 100644
--- a/app/code/community/Fishpig/Wordpress/Helper/Config.php
+++ b/app/code/community/Fishpig/Wordpress/Helper/Config.php
@@ -83,26 +83,34 @@ class Fishpig_Wordpress_Helper_Config extends Fishpig_Wordpress_Helper_Abstract
);
}
- $resource = Mage::getSingleton('core/resource');
- $db = $resource->getConnection('core_read');
- $config = array();
-
- foreach($options as $scope => $scopeId) {
- $select = $db->select()
- ->from($resource->getTableName('core/config_data'), array('path', 'value'))
- ->where('path LIKE ?', 'wordpress%')
- ->where('scope=?', $scope)
- ->where('scope_id=?', $scopeId);
-
- if ($results = $db->fetchAll($select)) {
- foreach($results as $result) {
- if (!isset($config[$result['path']])) {
- $config[$result['path']] = $result['value'];
- }
- }
- }
- }
+ $collection = Mage::getModel('core/config_data')->getCollection();
+ $collection->getSelect()->reset(Zend_Db_Select::COLUMNS);
+ $collection->addFieldToSelect(array('path', 'value'));
+ $collection->addFieldToFilter('path', array('like' => 'wordpress%'));
+ $sql = array();
+ foreach($options as $scope => $scopeId) {
+ $sql[] = sprintf('(scope = \'%s\' AND scope_id = %u)', $scope, $scopeId);
+ }
+ $collection->getSelect()->where(
+ new Zend_Db_Expr('(' . implode(' OR ', $sql) . ')')
+ );
+ $collection->getSelect()->order(new Zend_Db_Expr('FIELD(scope, \'default\', \'websites\', \'stores\')'));
+ //check we can apply collection caching *wohoooo*
+ if (true === Mage::app()->useCache('collections') && true === Mage::app()->useCache('config')) {
+
+ $cache = Mage::app()->getCache();
+ $cache->setLifetime(86400);
+ $collection->initCache(
+ $cache,
+ 'wordpress_',
+ array('collections', 'config')
+ );
+ }
+ $config = array();
+ foreach ($collection as $item) {
+ $config[$item->getPath()] = $item->getValue();
+ }
$defaults = array(
Mage::getConfig()->getNode()->default->wordpress,
Mage::getConfig()->getNode()->default->wordpress_blog,
@bentideswell
Copy link

Do you have any data on how much this improves performance?

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