[*] FO : lots of performance improvements (removed or merged useless SQL queries)
This commit is contained in:
@@ -153,18 +153,22 @@ abstract class ModuleCore
|
||||
// If cache is not generated, we generate it
|
||||
if (self::$modules_cache == null && !is_array(self::$modules_cache))
|
||||
{
|
||||
// Join clause is done to check if the module is activated in current shop context
|
||||
$sql_limit_shop = 'SELECT COUNT(*) FROM `'._DB_PREFIX_.'module_shop` ms WHERE m.`id_module` = ms.`id_module` AND ms.`id_shop` = '.((is_object(Context::getContext()->shop) && $id = (int)Context::getContext()->shop->id) ? $id : 1);
|
||||
|
||||
$sql = 'SELECT m.`id_module`, m.`name`, ('.$sql_limit_shop.') as total FROM `'._DB_PREFIX_.'module` m';
|
||||
|
||||
// Result is cached
|
||||
$id_shop = (Validate::isLoadedObject($this->context->shop) ? $this->context->shop->id : 1);
|
||||
self::$modules_cache = array();
|
||||
$result = Db::getInstance()->executeS($sql);
|
||||
// Join clause is done to check if the module is activated in current shop context
|
||||
$result = Db::getInstance()->executeS('
|
||||
SELECT m.`id_module`, m.`name`, (
|
||||
SELECT id_module
|
||||
FROM `'._DB_PREFIX_.'module_shop` ms
|
||||
WHERE m.`id_module` = ms.`id_module`
|
||||
AND ms.`id_shop` = '.(int)$id_shop.'
|
||||
LIMIT 1
|
||||
) as mshop
|
||||
FROM `'._DB_PREFIX_.'module` m');
|
||||
foreach ($result as $row)
|
||||
{
|
||||
self::$modules_cache[$row['name']] = $row;
|
||||
self::$modules_cache[$row['name']]['active'] = ($row['total'] > 0) ? 1 : 0;
|
||||
self::$modules_cache[$row['name']]['active'] = ($row['mshop'] > 0) ? 1 : 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1511,12 +1515,12 @@ abstract class ModuleCore
|
||||
* @param int $id_hook Hook ID
|
||||
* @return array Exceptions
|
||||
*/
|
||||
protected static $exceptionsCache = null;
|
||||
public function getExceptions($hookID, $dispatch = false)
|
||||
public function getExceptions($id_hook, $dispatch = false)
|
||||
{
|
||||
if (self::$exceptionsCache === null)
|
||||
$cache_id = 'exceptionsCache';
|
||||
if (!Cache::isStored($cache_id))
|
||||
{
|
||||
self::$exceptionsCache = array();
|
||||
$exceptionsCache = array();
|
||||
$sql = 'SELECT * FROM `'._DB_PREFIX_.'hook_module_exceptions`
|
||||
WHERE `id_shop` IN ('.implode(', ', Shop::getContextListShopID()).')';
|
||||
$result = Db::getInstance()->executeS($sql);
|
||||
@@ -1525,33 +1529,34 @@ abstract class ModuleCore
|
||||
if (!$row['file_name'])
|
||||
continue;
|
||||
$key = $row['id_hook'].'-'.$row['id_module'];
|
||||
if (!isset(self::$exceptionsCache[$key]))
|
||||
self::$exceptionsCache[$key] = array();
|
||||
if (!isset(self::$exceptionsCache[$key][$row['id_shop']]))
|
||||
self::$exceptionsCache[$key][$row['id_shop']] = array();
|
||||
self::$exceptionsCache[$key][$row['id_shop']][] = $row['file_name'];
|
||||
if (!isset($exceptionsCache[$key]))
|
||||
$exceptionsCache[$key] = array();
|
||||
if (!isset($exceptionsCache[$key][$row['id_shop']]))
|
||||
$exceptionsCache[$key][$row['id_shop']] = array();
|
||||
$exceptionsCache[$key][$row['id_shop']][] = $row['file_name'];
|
||||
}
|
||||
Cache::store($cache_id, $exceptionsCache);
|
||||
}
|
||||
else
|
||||
$exceptionsCache = !Cache::retrieve($cache_id);
|
||||
|
||||
$key = $hookID.'-'.$this->id;
|
||||
if (!$dispatch)
|
||||
$key = $id_hook.'-'.$this->id;
|
||||
$array_return = array();
|
||||
if ($dispatch)
|
||||
{
|
||||
$files = array();
|
||||
foreach (Shop::getContextListShopID() as $shop_id)
|
||||
if (isset(self::$exceptionsCache[$key], self::$exceptionsCache[$key][$shop_id]))
|
||||
foreach (self::$exceptionsCache[$key][$shop_id] as $file)
|
||||
if (!in_array($file, $files))
|
||||
$files[] = $file;
|
||||
return $files;
|
||||
if (isset($exceptionsCache[$key], $exceptionsCache[$key][$shop_id]))
|
||||
$array_return[$shop_id] = $exceptionsCache[$key][$shop_id];
|
||||
}
|
||||
else
|
||||
{
|
||||
$list = array();
|
||||
foreach (Shop::getContextListShopID() as $shop_id)
|
||||
if (isset(self::$exceptionsCache[$key], self::$exceptionsCache[$key][$shop_id]))
|
||||
$list[$shop_id] = self::$exceptionsCache[$key][$shop_id];
|
||||
return $list;
|
||||
if (isset($exceptionsCache[$key], $exceptionsCache[$key][$shop_id]))
|
||||
foreach ($exceptionsCache[$key][$shop_id] as $file)
|
||||
if (!in_array($file, $array_return))
|
||||
$array_return[] = $file;
|
||||
}
|
||||
return $array_return;
|
||||
}
|
||||
|
||||
public static function isInstalled($module_name)
|
||||
|
||||
Reference in New Issue
Block a user