// Multishop optimizations
This commit is contained in:
1 parent
d6079f42ff
commit
12111a4ee3
6 files changed
+60
-50
No files matched your search
+24
-15
@@ -180,13 +180,12 @@ class HookCore extends ObjectModel
|
|||||||
$cache_id = 'hook_module_list';
|
$cache_id = 'hook_module_list';
|
||||||
if (!Cache::isStored($cache_id))
|
if (!Cache::isStored($cache_id))
|
||||||
{
|
{
|
||||||
$sql = 'SELECT h.id_hook, h.name as h_name, title, description, h.position, live_edit, hm.position as hm_position, m.id_module, m.name, active
|
$results = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
|
||||||
FROM `'._DB_PREFIX_.'hook` h
|
SELECT h.id_hook, h.name as h_name, title, description, h.position, live_edit, hm.position as hm_position, m.id_module, m.name, active
|
||||||
INNER JOIN `'._DB_PREFIX_.'hook_module` hm ON (h.id_hook = hm.id_hook)
|
FROM `'._DB_PREFIX_.'hook` h
|
||||||
INNER JOIN `'._DB_PREFIX_.'module` as m ON (m.id_module = hm.id_module)
|
INNER JOIN `'._DB_PREFIX_.'hook_module` hm ON (h.id_hook = hm.id_hook AND hm.id_shop = '.(int)Context::getContext()->shop->id.')
|
||||||
WHERE hm.id_shop IN('.implode(', ', Shop::getContextListShopID()).')
|
INNER JOIN `'._DB_PREFIX_.'module` as m ON (m.id_module = hm.id_module)
|
||||||
ORDER BY hm.position';
|
ORDER BY hm.position');
|
||||||
$results = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
|
|
||||||
$list = array();
|
$list = array();
|
||||||
foreach ($results as $result)
|
foreach ($results as $result)
|
||||||
{
|
{
|
||||||
@@ -245,22 +244,32 @@ class HookCore extends ObjectModel
|
|||||||
$cache_id = 'hook_module_exec_list'.((isset($context->customer)) ? '_'.$context->customer->id : '');
|
$cache_id = 'hook_module_exec_list'.((isset($context->customer)) ? '_'.$context->customer->id : '');
|
||||||
if (!Cache::isStored($cache_id))
|
if (!Cache::isStored($cache_id))
|
||||||
{
|
{
|
||||||
// Get shops and groups list
|
$frontend = true;
|
||||||
$shop_list = Shop::getContextListShopID();
|
$groups = array();
|
||||||
if (isset($context->customer) && $context->customer->isLogged())
|
if (isset($context->employee))
|
||||||
$groups = $context->customer->getGroups();
|
{
|
||||||
|
$shop_list = array((int)$context->shop->id);
|
||||||
|
$frontend = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Get shops and groups list
|
||||||
|
$shop_list = Shop::getContextListShopID();
|
||||||
|
if (isset($context->customer) && $context->customer->isLogged())
|
||||||
|
$groups = $context->customer->getGroups();
|
||||||
|
}
|
||||||
|
|
||||||
// SQL Request
|
// SQL Request
|
||||||
$sql = new DbQuery();
|
$sql = new DbQuery();
|
||||||
$sql->select('h.`name` as hook, m.`id_module`, h.`id_hook`, m.`name` as module, h.`live_edit`');
|
$sql->select('h.`name` as hook, m.`id_module`, h.`id_hook`, m.`name` as module, h.`live_edit`');
|
||||||
$sql->from('module', 'm');
|
$sql->from('module', 'm');
|
||||||
$sql->innerJoin('hook_module', 'hm', 'hm.`id_module` = m.`id_module`');
|
$sql->innerJoin('hook_module', 'hm', 'hm.`id_module` = m.`id_module`');
|
||||||
$sql->innerJoin('hook', 'h', 'hm.`id_hook` = h.`id_hook`');
|
$sql->innerJoin('hook', 'h', 'hm.`id_hook` = h.`id_hook`');
|
||||||
$sql->where('(SELECT COUNT(*) FROM '._DB_PREFIX_.'module_shop ms WHERE ms.id_module = m.id_module AND ms.id_shop IN('.implode(', ', $shop_list).')) = '.count($shop_list));
|
$sql->where('(SELECT COUNT(*) FROM '._DB_PREFIX_.'module_shop ms WHERE ms.id_module = m.id_module AND ms.id_shop IN ('.implode(', ', $shop_list).')) = '.count($shop_list));
|
||||||
// For payment modules, we check that they are available in the contextual country
|
// For payment modules, we check that they are available in the contextual country
|
||||||
if (Validate::isLoadedObject($context->country))
|
if ($frontend && Validate::isLoadedObject($context->country))
|
||||||
$sql->where('(h.name != "displayPayment" OR (SELECT id_country FROM '._DB_PREFIX_.'module_country mc WHERE mc.id_module = m.id_module AND id_country = '.(int)$context->country->id.' LIMIT 1) = '.(int)$context->country->id.')');
|
$sql->where('(h.name != "displayPayment" OR (SELECT id_country FROM '._DB_PREFIX_.'module_country mc WHERE mc.id_module = m.id_module AND id_country = '.(int)$context->country->id.' LIMIT 1) = '.(int)$context->country->id.')');
|
||||||
$sql->where('hm.id_shop IN ('.implode(', ', $shop_list).')');
|
$sql->where('hm.id_shop = '.(int)$context->shop->id);
|
||||||
|
|
||||||
if (isset($context->customer) && $context->customer->isLogged())
|
if (isset($context->customer) && $context->customer->isLogged())
|
||||||
{
|
{
|
||||||
|
|||||||
+9
-7
@@ -2441,13 +2441,15 @@ class ProductCore extends ObjectModel
|
|||||||
if (Combination::isFeatureActive())
|
if (Combination::isFeatureActive())
|
||||||
{
|
{
|
||||||
$default_on = true;
|
$default_on = true;
|
||||||
$sql->select('pa.id_product_attribute, product_attribute_shop.`price` AS attribute_price, (SELECT product_attribute_shop.price
|
$sql->select('pa.id_product_attribute, product_attribute_shop.`price` AS attribute_price, (
|
||||||
FROM `'._DB_PREFIX_.'product_attribute` pa
|
SELECT product_attribute_shop.price
|
||||||
'.Shop::addSqlAssociation('product_attribute', 'pa').'
|
FROM `'._DB_PREFIX_.'product_attribute` pa
|
||||||
WHERE pa.id_product = '.(int)$id_product.'
|
'.Shop::addSqlAssociation('product_attribute', 'pa').'
|
||||||
AND product_attribute_shop.default_on = 1
|
WHERE pa.id_product = '.(int)$id_product.'
|
||||||
GROUP BY pa.id_product_attribute
|
AND product_attribute_shop.default_on = 1
|
||||||
LIMIT 1) as default_on');
|
GROUP BY pa.id_product_attribute
|
||||||
|
LIMIT 1
|
||||||
|
) as default_on');
|
||||||
$sql->leftJoin('product_attribute', 'pa', 'pa.`id_product` = '.(int)$id_product);
|
$sql->leftJoin('product_attribute', 'pa', 'pa.`id_product` = '.(int)$id_product);
|
||||||
$sql->join(Shop::addSqlAssociation('product_attribute', 'pa', false));
|
$sql->join(Shop::addSqlAssociation('product_attribute', 'pa', false));
|
||||||
}
|
}
|
||||||
|
|||||||
+19
-22
@@ -1289,8 +1289,11 @@ abstract class ModuleCore
|
|||||||
if (isset($context->cart))
|
if (isset($context->cart))
|
||||||
$billing = new Address((int)$context->cart->id_address_invoice);
|
$billing = new Address((int)$context->cart->id_address_invoice);
|
||||||
|
|
||||||
|
$frontend = true;
|
||||||
$groups = array();
|
$groups = array();
|
||||||
if (isset($context->customer))
|
if (isset($context->employee))
|
||||||
|
$frontend = false;
|
||||||
|
elseif (isset($context->customer))
|
||||||
{
|
{
|
||||||
$groups = $context->customer->getGroups();
|
$groups = $context->customer->getGroups();
|
||||||
if (empty($groups))
|
if (empty($groups))
|
||||||
@@ -1302,27 +1305,21 @@ abstract class ModuleCore
|
|||||||
$hookPayment = 'displayPayment';
|
$hookPayment = 'displayPayment';
|
||||||
|
|
||||||
$list = Shop::getContextListShopID();
|
$list = Shop::getContextListShopID();
|
||||||
$sql = 'SELECT DISTINCT h.`id_hook`, m.`name`, hm.`position`
|
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
|
||||||
FROM `'._DB_PREFIX_.'module_country` mc
|
SELECT DISTINCT h.`id_hook`, m.`name`, hm.`position`
|
||||||
LEFT JOIN `'._DB_PREFIX_.'module` m ON m.`id_module` = mc.`id_module`
|
FROM `'._DB_PREFIX_.'module` m
|
||||||
INNER JOIN `'._DB_PREFIX_.'module_group` mg ON (m.`id_module` = mg.`id_module`)
|
'.($frontend ? 'LEFT JOIN `'._DB_PREFIX_.'module_country` mc ON (m.`id_module` = mc.`id_module` AND mc.id_shop = '.(int)$context->shop->id.')' : '').'
|
||||||
'.(isset($context->customer)
|
'.($frontend ? 'INNER JOIN `'._DB_PREFIX_.'module_group` mg ON (m.`id_module` = mg.`id_module` AND mg.id_shop = '.(int)$context->shop->id.')' : '').'
|
||||||
? 'INNER JOIN `'._DB_PREFIX_.'customer_group` cg on (cg.`id_group` = mg.`id_group`AND cg.`id_customer` = '.(int)$context->customer->id.')'
|
'.(isset($context->customer) ? 'INNER JOIN `'._DB_PREFIX_.'customer_group` cg on (cg.`id_group` = mg.`id_group`AND cg.`id_customer` = '.(int)$context->customer->id.')' : '').'
|
||||||
: '').'
|
LEFT JOIN `'._DB_PREFIX_.'hook_module` hm ON hm.`id_module` = m.`id_module`
|
||||||
LEFT JOIN `'._DB_PREFIX_.'hook_module` hm ON hm.`id_module` = m.`id_module`
|
LEFT JOIN `'._DB_PREFIX_.'hook` h ON hm.`id_hook` = h.`id_hook`
|
||||||
LEFT JOIN `'._DB_PREFIX_.'hook` h ON hm.`id_hook` = h.`id_hook`
|
WHERE h.`name` = \''.pSQL($hookPayment).'\'
|
||||||
WHERE h.`name` = \''.pSQL($hookPayment).'\'
|
'.(isset($billing) && $frontend ? 'AND mc.id_country = '.(int)$billing->id_country : '').'
|
||||||
'.(isset($billing) ? 'AND mc.id_country = '.(int)$billing->id_country : '').'
|
AND (SELECT COUNT(*) FROM '._DB_PREFIX_.'module_shop ms WHERE ms.id_module = m.id_module AND ms.id_shop IN('.implode(', ', $list).')) = '.count($list).'
|
||||||
AND mc.id_shop = '.(int)$context->shop->id.'
|
AND hm.id_shop IN('.implode(', ', $list).')
|
||||||
AND mg.id_shop = '.(int)$context->shop->id.'
|
'.(count($groups) && $frontend ? 'AND (mg.`id_group` IN('.implode(', ', $groups).'))' : '').'
|
||||||
AND (SELECT COUNT(*) FROM '._DB_PREFIX_.'module_shop ms WHERE ms.id_module = m.id_module AND ms.id_shop IN('.implode(', ', $list).')) = '.count($list).'
|
GROUP BY hm.id_hook, hm.id_module
|
||||||
AND hm.id_shop IN('.implode(', ', $list).')
|
ORDER BY hm.`position`, m.`name` DESC');
|
||||||
'.(count($groups) ? 'AND (mg.`id_group` IN('.implode(', ', $groups).'))' : '').'
|
|
||||||
GROUP BY hm.id_hook, hm.id_module
|
|
||||||
ORDER BY hm.`position`, m.`name` DESC';
|
|
||||||
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ abstract class ModuleGridCore extends Module
|
|||||||
{
|
{
|
||||||
if (!Validate::isModuleName($render))
|
if (!Validate::isModuleName($render))
|
||||||
die(Tools::displayError());
|
die(Tools::displayError());
|
||||||
if (!Tools::file_exists_cache($file = dirname(__FILE__).'/../../modules/'.$render.'/'.$render.'.php'))
|
if (!Tools::file_exists_cache($file = _PS_ROOT_DIR_.'/modules/'.$render.'/'.$render.'.php'))
|
||||||
die(Tools::displayError());
|
die(Tools::displayError());
|
||||||
require_once($file);
|
require_once($file);
|
||||||
$this->_render = new $render($type);
|
$this->_render = new $render($type);
|
||||||
@@ -99,7 +99,7 @@ abstract class ModuleGridCore extends Module
|
|||||||
return Tools::displayError('No grid engine selected');
|
return Tools::displayError('No grid engine selected');
|
||||||
if (!Validate::isModuleName($render))
|
if (!Validate::isModuleName($render))
|
||||||
die(Tools::displayError());
|
die(Tools::displayError());
|
||||||
if (!file_exists(dirname(__FILE__).'/../../modules/'.$render.'/'.$render.'.php'))
|
if (!file_exists(_PS_ROOT_DIR_.'/modules/'.$render.'/'.$render.'.php'))
|
||||||
return Tools::displayError('Grid engine selected is unavailable.');
|
return Tools::displayError('Grid engine selected is unavailable.');
|
||||||
|
|
||||||
$grider = 'grider.php?render='.$render.'&module='.Tools::safeOutput(Tools::getValue('module'));
|
$grider = 'grider.php?render='.$render.'&module='.Tools::safeOutput(Tools::getValue('module'));
|
||||||
@@ -132,7 +132,7 @@ abstract class ModuleGridCore extends Module
|
|||||||
if (isset($params['dir']) && Validate::isSortDirection($params['dir']))
|
if (isset($params['dir']) && Validate::isSortDirection($params['dir']))
|
||||||
$grider .= '&dir='.$params['dir'];
|
$grider .= '&dir='.$params['dir'];
|
||||||
|
|
||||||
require_once(dirname(__FILE__).'/../../modules/'.$render.'/'.$render.'.php');
|
require_once(_PS_ROOT_DIR_.'/modules/'.$render.'/'.$render.'.php');
|
||||||
return call_user_func(array($render, 'hookGridEngine'), $params, $grider);
|
return call_user_func(array($render, 'hookGridEngine'), $params, $grider);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -888,9 +888,9 @@ class ShopCore extends ObjectModel
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
$sql = (($inner_join) ? ' INNER' : ' LEFT').' JOIN '._DB_PREFIX_.$table.'_shop '.$table_alias.'
|
$sql = (($inner_join) ? ' INNER' : ' LEFT').' JOIN '._DB_PREFIX_.$table.'_shop '.$table_alias.'
|
||||||
ON '.$table_alias.'.id_'.$table.' = '.$alias.'.id_'.$table.'
|
ON '.$table_alias.'.id_'.$table.' = '.$alias.'.id_'.$table.'
|
||||||
AND '.$table_alias.'.id_shop IN('.implode(', ', Shop::getContextListShopID()).') '
|
AND '.$table_alias.'.id_shop IN ('.implode(', ', Shop::getContextListShopID()).')
|
||||||
.(($on) ? ' AND '.$on : '');
|
'.(($on) ? ' AND '.$on : '');
|
||||||
return $sql;
|
return $sql;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -396,6 +396,8 @@ abstract class Controller extends ControllerCore
|
|||||||
foreach ($explain as $row)
|
foreach ($explain as $row)
|
||||||
$browsed_rows *= $row['rows'];
|
$browsed_rows *= $row['rows'];
|
||||||
echo $this->displayRowsBrowsed($browsed_rows);
|
echo $this->displayRowsBrowsed($browsed_rows);
|
||||||
|
if (stristr($data['query'], 'group by') && !preg_match('/(avg|count|min|max|group_concat|sum)\s*\(/i', $data['query']))
|
||||||
|
echo '<br /><b>Useless GROUP BY need to be removed</b>';
|
||||||
}
|
}
|
||||||
echo '</div>
|
echo '</div>
|
||||||
<div class="rte" style="text-align:left;padding:8px">
|
<div class="rte" style="text-align:left;padding:8px">
|
||||||
|
|||||||
Reference in new issue
Block a user