// Multishop optimizations
This commit is contained in:
+24
-15
@@ -180,13 +180,12 @@ class HookCore extends ObjectModel
|
||||
$cache_id = 'hook_module_list';
|
||||
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
|
||||
FROM `'._DB_PREFIX_.'hook` h
|
||||
INNER JOIN `'._DB_PREFIX_.'hook_module` hm ON (h.id_hook = hm.id_hook)
|
||||
INNER JOIN `'._DB_PREFIX_.'module` as m ON (m.id_module = hm.id_module)
|
||||
WHERE hm.id_shop IN('.implode(', ', Shop::getContextListShopID()).')
|
||||
ORDER BY hm.position';
|
||||
$results = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
|
||||
$results = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
|
||||
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
|
||||
FROM `'._DB_PREFIX_.'hook` h
|
||||
INNER JOIN `'._DB_PREFIX_.'hook_module` hm ON (h.id_hook = hm.id_hook AND hm.id_shop = '.(int)Context::getContext()->shop->id.')
|
||||
INNER JOIN `'._DB_PREFIX_.'module` as m ON (m.id_module = hm.id_module)
|
||||
ORDER BY hm.position');
|
||||
$list = array();
|
||||
foreach ($results as $result)
|
||||
{
|
||||
@@ -245,22 +244,32 @@ class HookCore extends ObjectModel
|
||||
$cache_id = 'hook_module_exec_list'.((isset($context->customer)) ? '_'.$context->customer->id : '');
|
||||
if (!Cache::isStored($cache_id))
|
||||
{
|
||||
// Get shops and groups list
|
||||
$shop_list = Shop::getContextListShopID();
|
||||
if (isset($context->customer) && $context->customer->isLogged())
|
||||
$groups = $context->customer->getGroups();
|
||||
|
||||
$frontend = true;
|
||||
$groups = array();
|
||||
if (isset($context->employee))
|
||||
{
|
||||
$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 = new DbQuery();
|
||||
$sql->select('h.`name` as hook, m.`id_module`, h.`id_hook`, m.`name` as module, h.`live_edit`');
|
||||
$sql->from('module', 'm');
|
||||
$sql->innerJoin('hook_module', 'hm', 'hm.`id_module` = m.`id_module`');
|
||||
$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
|
||||
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('hm.id_shop IN ('.implode(', ', $shop_list).')');
|
||||
$sql->where('hm.id_shop = '.(int)$context->shop->id);
|
||||
|
||||
if (isset($context->customer) && $context->customer->isLogged())
|
||||
{
|
||||
|
||||
+9
-7
@@ -2441,13 +2441,15 @@ class ProductCore extends ObjectModel
|
||||
if (Combination::isFeatureActive())
|
||||
{
|
||||
$default_on = true;
|
||||
$sql->select('pa.id_product_attribute, product_attribute_shop.`price` AS attribute_price, (SELECT product_attribute_shop.price
|
||||
FROM `'._DB_PREFIX_.'product_attribute` pa
|
||||
'.Shop::addSqlAssociation('product_attribute', 'pa').'
|
||||
WHERE pa.id_product = '.(int)$id_product.'
|
||||
AND product_attribute_shop.default_on = 1
|
||||
GROUP BY pa.id_product_attribute
|
||||
LIMIT 1) as default_on');
|
||||
$sql->select('pa.id_product_attribute, product_attribute_shop.`price` AS attribute_price, (
|
||||
SELECT product_attribute_shop.price
|
||||
FROM `'._DB_PREFIX_.'product_attribute` pa
|
||||
'.Shop::addSqlAssociation('product_attribute', 'pa').'
|
||||
WHERE pa.id_product = '.(int)$id_product.'
|
||||
AND product_attribute_shop.default_on = 1
|
||||
GROUP BY pa.id_product_attribute
|
||||
LIMIT 1
|
||||
) as default_on');
|
||||
$sql->leftJoin('product_attribute', 'pa', 'pa.`id_product` = '.(int)$id_product);
|
||||
$sql->join(Shop::addSqlAssociation('product_attribute', 'pa', false));
|
||||
}
|
||||
|
||||
+19
-22
@@ -1289,8 +1289,11 @@ abstract class ModuleCore
|
||||
if (isset($context->cart))
|
||||
$billing = new Address((int)$context->cart->id_address_invoice);
|
||||
|
||||
$frontend = true;
|
||||
$groups = array();
|
||||
if (isset($context->customer))
|
||||
if (isset($context->employee))
|
||||
$frontend = false;
|
||||
elseif (isset($context->customer))
|
||||
{
|
||||
$groups = $context->customer->getGroups();
|
||||
if (empty($groups))
|
||||
@@ -1302,27 +1305,21 @@ abstract class ModuleCore
|
||||
$hookPayment = 'displayPayment';
|
||||
|
||||
$list = Shop::getContextListShopID();
|
||||
$sql = 'SELECT DISTINCT h.`id_hook`, m.`name`, hm.`position`
|
||||
FROM `'._DB_PREFIX_.'module_country` mc
|
||||
LEFT JOIN `'._DB_PREFIX_.'module` m ON m.`id_module` = mc.`id_module`
|
||||
INNER JOIN `'._DB_PREFIX_.'module_group` mg ON (m.`id_module` = mg.`id_module`)
|
||||
'.(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` h ON hm.`id_hook` = h.`id_hook`
|
||||
WHERE h.`name` = \''.pSQL($hookPayment).'\'
|
||||
'.(isset($billing) ? 'AND mc.id_country = '.(int)$billing->id_country : '').'
|
||||
AND mc.id_shop = '.(int)$context->shop->id.'
|
||||
AND mg.id_shop = '.(int)$context->shop->id.'
|
||||
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 hm.id_shop IN('.implode(', ', $list).')
|
||||
'.(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;
|
||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
|
||||
SELECT DISTINCT h.`id_hook`, m.`name`, hm.`position`
|
||||
FROM `'._DB_PREFIX_.'module` m
|
||||
'.($frontend ? 'LEFT JOIN `'._DB_PREFIX_.'module_country` mc ON (m.`id_module` = mc.`id_module` AND mc.id_shop = '.(int)$context->shop->id.')' : '').'
|
||||
'.($frontend ? 'INNER JOIN `'._DB_PREFIX_.'module_group` mg ON (m.`id_module` = mg.`id_module` AND mg.id_shop = '.(int)$context->shop->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` h ON hm.`id_hook` = h.`id_hook`
|
||||
WHERE h.`name` = \''.pSQL($hookPayment).'\'
|
||||
'.(isset($billing) && $frontend ? '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 hm.id_shop IN('.implode(', ', $list).')
|
||||
'.(count($groups) && $frontend ? 'AND (mg.`id_group` IN('.implode(', ', $groups).'))' : '').'
|
||||
GROUP BY hm.id_hook, hm.id_module
|
||||
ORDER BY hm.`position`, m.`name` DESC');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -69,7 +69,7 @@ abstract class ModuleGridCore extends Module
|
||||
{
|
||||
if (!Validate::isModuleName($render))
|
||||
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());
|
||||
require_once($file);
|
||||
$this->_render = new $render($type);
|
||||
@@ -99,7 +99,7 @@ abstract class ModuleGridCore extends Module
|
||||
return Tools::displayError('No grid engine selected');
|
||||
if (!Validate::isModuleName($render))
|
||||
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.');
|
||||
|
||||
$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']))
|
||||
$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);
|
||||
}
|
||||
|
||||
|
||||
@@ -888,9 +888,9 @@ class ShopCore extends ObjectModel
|
||||
return;
|
||||
|
||||
$sql = (($inner_join) ? ' INNER' : ' LEFT').' JOIN '._DB_PREFIX_.$table.'_shop '.$table_alias.'
|
||||
ON '.$table_alias.'.id_'.$table.' = '.$alias.'.id_'.$table.'
|
||||
AND '.$table_alias.'.id_shop IN('.implode(', ', Shop::getContextListShopID()).') '
|
||||
.(($on) ? ' AND '.$on : '');
|
||||
ON '.$table_alias.'.id_'.$table.' = '.$alias.'.id_'.$table.'
|
||||
AND '.$table_alias.'.id_shop IN ('.implode(', ', Shop::getContextListShopID()).')
|
||||
'.(($on) ? ' AND '.$on : '');
|
||||
return $sql;
|
||||
}
|
||||
|
||||
|
||||
@@ -396,6 +396,8 @@ abstract class Controller extends ControllerCore
|
||||
foreach ($explain as $row)
|
||||
$browsed_rows *= $row['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>
|
||||
<div class="rte" style="text-align:left;padding:8px">
|
||||
|
||||
Reference in New Issue
Block a user