[*] FO : Code cleaning, optimizations, new callstack available in the profiling tools
This commit is contained in:
1 parent
5c3f43141b
commit
9dc075ca39
5 files changed
+60
-73
No files matched your search
+14
-17
@@ -207,16 +207,15 @@ class CurrencyCore extends ObjectModel
|
|||||||
*
|
*
|
||||||
* @return array Currencies
|
* @return array Currencies
|
||||||
*/
|
*/
|
||||||
public static function getCurrencies($object = false, $active = 1)
|
public static function getCurrencies($object = false, $active = true)
|
||||||
{
|
{
|
||||||
$sql = 'SELECT *
|
$tab = Db::getInstance()->executeS('
|
||||||
FROM `'._DB_PREFIX_.'currency` c
|
SELECT *
|
||||||
'.Shop::addSqlAssociation('currency', 'c').'
|
FROM `'._DB_PREFIX_.'currency` c
|
||||||
WHERE `deleted` = 0'
|
'.Shop::addSqlAssociation('currency', 'c').'
|
||||||
.($active == 1 ? ' AND c.`active` = 1' : '').'
|
WHERE `deleted` = 0
|
||||||
GROUP BY c.id_currency
|
'.($active ? ' AND c.`active` = 1' : '').'
|
||||||
ORDER BY `name` ASC';
|
ORDER BY `name` ASC');
|
||||||
$tab = Db::getInstance()->executeS($sql);
|
|
||||||
if ($object)
|
if ($object)
|
||||||
foreach ($tab as $key => $currency)
|
foreach ($tab as $key => $currency)
|
||||||
$tab[$key] = Currency::getCurrencyInstance($currency['id_currency']);
|
$tab[$key] = Currency::getCurrencyInstance($currency['id_currency']);
|
||||||
@@ -225,14 +224,12 @@ class CurrencyCore extends ObjectModel
|
|||||||
|
|
||||||
public static function getCurrenciesByIdShop($id_shop = 0)
|
public static function getCurrenciesByIdShop($id_shop = 0)
|
||||||
{
|
{
|
||||||
$sql = 'SELECT *
|
return Db::getInstance()->executeS('
|
||||||
FROM `'._DB_PREFIX_.'currency` c
|
SELECT *
|
||||||
LEFT JOIN `'._DB_PREFIX_.'currency_shop` cs ON (cs.`id_currency` = c.`id_currency`)
|
FROM `'._DB_PREFIX_.'currency` c
|
||||||
'.($id_shop != 0 ? ' WHERE cs.`id_shop` = '.(int)$id_shop : '').'
|
LEFT JOIN `'._DB_PREFIX_.'currency_shop` cs ON (cs.`id_currency` = c.`id_currency`)
|
||||||
GROUP BY c.id_currency
|
'.($id_shop ? ' WHERE cs.`id_shop` = '.(int)$id_shop : '').'
|
||||||
ORDER BY `name` ASC';
|
ORDER BY `name` ASC');
|
||||||
|
|
||||||
return Db::getInstance()->executeS($sql);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+22
-39
@@ -162,22 +162,14 @@ class ManufacturerCore extends ObjectModel
|
|||||||
if (!Group::isFeatureActive())
|
if (!Group::isFeatureActive())
|
||||||
$all_group = true;
|
$all_group = true;
|
||||||
|
|
||||||
$sql = 'SELECT m.*, ml.`description`, ml.`short_description`
|
$manufacturers = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
|
||||||
FROM `'._DB_PREFIX_.'manufacturer` m
|
SELECT m.*, ml.`description`, ml.`short_description`
|
||||||
LEFT JOIN `'._DB_PREFIX_.'manufacturer_lang` ml ON (
|
FROM `'._DB_PREFIX_.'manufacturer` m
|
||||||
m.`id_manufacturer` = ml.`id_manufacturer`
|
'.Shop::addSqlAssociation('manufacturer', 'm').'
|
||||||
AND ml.`id_lang` = '.(int)$id_lang.'
|
INNER JOIN `'._DB_PREFIX_.'manufacturer_lang` ml ON (m.`id_manufacturer` = ml.`id_manufacturer` AND ml.`id_lang` = '.(int)$id_lang.')
|
||||||
)
|
'.($active ? 'WHERE m.`active` = 1' : '').'
|
||||||
'.Shop::addSqlAssociation('manufacturer', 'm');
|
ORDER BY m.`name` ASC
|
||||||
if ($active)
|
'.($p ? ' LIMIT '.(((int)$p - 1) * (int)$n).','.(int)$n : ''));
|
||||||
$sql .= '
|
|
||||||
WHERE m.`active` = 1';
|
|
||||||
$sql .= '
|
|
||||||
GROUP BY m.id_manufacturer
|
|
||||||
ORDER BY m.`name` ASC'.
|
|
||||||
($p ? ' LIMIT '.(((int)$p - 1) * (int)$n).','.(int)$n : '');
|
|
||||||
|
|
||||||
$manufacturers = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
|
|
||||||
if ($manufacturers === false)
|
if ($manufacturers === false)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@@ -192,35 +184,26 @@ class ManufacturerCore extends ObjectModel
|
|||||||
|
|
||||||
foreach ($manufacturers as $key => $manufacturer)
|
foreach ($manufacturers as $key => $manufacturer)
|
||||||
{
|
{
|
||||||
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(
|
$manufacturers[$key]['nb_products'] = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
|
||||||
'SELECT p.`id_product`
|
SELECT COUNT(DISTINCT p.`id_product`)
|
||||||
FROM `'._DB_PREFIX_.'product` p
|
FROM `'._DB_PREFIX_.'product` p
|
||||||
'.Shop::addSqlAssociation('product', 'p').'
|
'.Shop::addSqlAssociation('product', 'p').'
|
||||||
LEFT JOIN `'._DB_PREFIX_.'manufacturer` as m ON (m.`id_manufacturer`= p.`id_manufacturer`)
|
WHERE p.`id_manufacturer` = '.(int)$manufacturer['id_manufacturer'].'
|
||||||
WHERE m.`id_manufacturer` = '.(int)$manufacturer['id_manufacturer'].
|
AND product_shop.`visibility` NOT IN ("none")
|
||||||
($active ? ' AND product_shop.`active` = 1 ' : '').
|
'.($active ? ' AND product_shop.`active` = 1 ' : '').'
|
||||||
' AND product_shop.`visibility` NOT IN ("none")'.
|
'.($all_group ? '' : ' AND p.`id_product` IN (
|
||||||
($all_group ? '' : ' AND p.`id_product` IN (
|
SELECT cp.`id_product`
|
||||||
SELECT cp.`id_product`
|
FROM `'._DB_PREFIX_.'category_group` cg
|
||||||
FROM `'._DB_PREFIX_.'category_group` cg
|
LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_category` = cg.`id_category`)
|
||||||
LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_category` = cg.`id_category`)
|
WHERE cg.`id_group` '.$sql_groups.'
|
||||||
WHERE cg.`id_group` '.$sql_groups.'
|
)'));
|
||||||
)')
|
|
||||||
);
|
|
||||||
|
|
||||||
$manufacturers[$key]['nb_products'] = count($result);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$total_manufacturers = count($manufacturers);
|
$total_manufacturers = count($manufacturers);
|
||||||
$rewrite_settings = (int)Configuration::get('PS_REWRITING_SETTINGS');
|
$rewrite_settings = (int)Configuration::get('PS_REWRITING_SETTINGS');
|
||||||
|
|
||||||
for ($i = 0; $i < $total_manufacturers; $i++)
|
for ($i = 0; $i < $total_manufacturers; $i++)
|
||||||
if ($rewrite_settings)
|
$manufacturers[$i]['link_rewrite'] = ($rewrite_settings ? Tools::link_rewrite($manufacturers[$i]['name']) : 0);
|
||||||
$manufacturers[$i]['link_rewrite'] = Tools::link_rewrite($manufacturers[$i]['name']);
|
|
||||||
else
|
|
||||||
$manufacturers[$i]['link_rewrite'] = 0;
|
|
||||||
|
|
||||||
return $manufacturers;
|
return $manufacturers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -119,7 +119,6 @@ class SupplierCore extends ObjectModel
|
|||||||
$query->where('s.`active` = 1');
|
$query->where('s.`active` = 1');
|
||||||
$query->orderBy(' s.`name` ASC');
|
$query->orderBy(' s.`name` ASC');
|
||||||
$query->limit($n, ($p - 1) * $n);
|
$query->limit($n, ($p - 1) * $n);
|
||||||
$query->groupBy('s.id_supplier');
|
|
||||||
|
|
||||||
$suppliers = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query);
|
$suppliers = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query);
|
||||||
if ($suppliers === false)
|
if ($suppliers === false)
|
||||||
@@ -159,10 +158,7 @@ class SupplierCore extends ObjectModel
|
|||||||
$nb_suppliers = count($suppliers);
|
$nb_suppliers = count($suppliers);
|
||||||
$rewrite_settings = (int)Configuration::get('PS_REWRITING_SETTINGS');
|
$rewrite_settings = (int)Configuration::get('PS_REWRITING_SETTINGS');
|
||||||
for ($i = 0; $i < $nb_suppliers; $i++)
|
for ($i = 0; $i < $nb_suppliers; $i++)
|
||||||
if ($rewrite_settings)
|
$suppliers[$i]['link_rewrite'] = ($rewrite_settings ? Tools::link_rewrite($suppliers[$i]['name']) : 0);
|
||||||
$suppliers[$i]['link_rewrite'] = Tools::link_rewrite($suppliers[$i]['name']);
|
|
||||||
else
|
|
||||||
$suppliers[$i]['link_rewrite'] = 0;
|
|
||||||
return $suppliers;
|
return $suppliers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -414,10 +414,11 @@ abstract class Controller extends ControllerCore
|
|||||||
$query_row = array(
|
$query_row = array(
|
||||||
'time' => $data['time'],
|
'time' => $data['time'],
|
||||||
'query' => $data['query'],
|
'query' => $data['query'],
|
||||||
'location' => $data['file'].':'.$data['line'],
|
'location' => $data['stack'][0]['file'].':'.$data['stack'][0]['line'],
|
||||||
'filesort' => false,
|
'filesort' => false,
|
||||||
'rows' => 1,
|
'rows' => 1,
|
||||||
'group_by' => false
|
'group_by' => false,
|
||||||
|
'stack' => $data['stack']
|
||||||
);
|
);
|
||||||
if (preg_match('/^\s*select\s+/i', $data['query']))
|
if (preg_match('/^\s*select\s+/i', $data['query']))
|
||||||
{
|
{
|
||||||
@@ -445,7 +446,7 @@ abstract class Controller extends ControllerCore
|
|||||||
<div id="queries_table" style="display:none;margin:4px">
|
<div id="queries_table" style="display:none;margin:4px">
|
||||||
<table class="table std">
|
<table class="table std">
|
||||||
<tr><th>Time (ms)</th><th>Rows</th><th>Query</th><th>Location</th><th>Filesort</th><th>Group By</th></tr>';
|
<tr><th>Time (ms)</th><th>Rows</th><th>Query</th><th>Location</th><th>Filesort</th><th>Group By</th></tr>';
|
||||||
foreach ($array_queries as $data)
|
foreach ($array_queries as &$data)
|
||||||
{
|
{
|
||||||
$data['location'] = str_replace('\\', '/', substr($data['location'], strlen(_PS_ROOT_DIR_)));
|
$data['location'] = str_replace('\\', '/', substr($data['location'], strlen(_PS_ROOT_DIR_)));
|
||||||
$data['query'] = str_replace('SQL_NO_CACHE ', '', $data['query']);
|
$data['query'] = str_replace('SQL_NO_CACHE ', '', $data['query']);
|
||||||
@@ -456,9 +457,18 @@ abstract class Controller extends ControllerCore
|
|||||||
</div>
|
</div>
|
||||||
<div class="rte" style="text-align:left;padding:8px">
|
<div class="rte" style="text-align:left;padding:8px">
|
||||||
<h3><a name="stopwatch">Stopwatch (with SQL_NO_CACHE) (total = '.count(Db::getInstance()->queries).')</a></h3>';
|
<h3><a name="stopwatch">Stopwatch (with SQL_NO_CACHE) (total = '.count(Db::getInstance()->queries).')</a></h3>';
|
||||||
|
$i = 1;
|
||||||
foreach ($array_queries as $data)
|
foreach ($array_queries as $data)
|
||||||
{
|
{
|
||||||
echo $hr.'<b '.$this->getTimeColor($data['time'] * 1000).'>'.round($data['time'] * 1000, 3).' ms</b> '.htmlspecialchars($data['query'], ENT_NOQUOTES, 'utf-8', false).'<br />in '.$data['location'].'<br />';
|
$echo_stack = '';
|
||||||
|
array_shift($data['stack']);
|
||||||
|
foreach ($data['stack'] as $call)
|
||||||
|
$echo_stack .= 'from '.str_replace('\\', '/', substr($call['file'], strlen(_PS_ROOT_DIR_))).':'.$call['line'].'<br />';
|
||||||
|
|
||||||
|
echo $hr.'<div onclick="$(\'#qbt'.$i.'\').toggle();"><b '.$this->getTimeColor($data['time'] * 1000).'>'.round($data['time'] * 1000, 3).' ms</b>
|
||||||
|
'.htmlspecialchars($data['query'], ENT_NOQUOTES, 'utf-8', false).'<br />
|
||||||
|
in '.$data['location'].'<br />
|
||||||
|
<div id="qbt'.($i++).'" style="display:none">'.$echo_stack.'</div>';
|
||||||
if (preg_match('/^\s*select\s+/i', $data['query']))
|
if (preg_match('/^\s*select\s+/i', $data['query']))
|
||||||
{
|
{
|
||||||
if ($data['filesort'])
|
if ($data['filesort'])
|
||||||
@@ -467,6 +477,7 @@ abstract class Controller extends ControllerCore
|
|||||||
if ($data['group_by'])
|
if ($data['group_by'])
|
||||||
echo '<br /><b>Useless GROUP BY need to be removed</b>';
|
echo '<br /><b>Useless GROUP BY need to be removed</b>';
|
||||||
}
|
}
|
||||||
|
echo '</div>';
|
||||||
}
|
}
|
||||||
$queries = Db::getInstance()->uniqQueries;
|
$queries = Db::getInstance()->uniqQueries;
|
||||||
arsort($queries);
|
arsort($queries);
|
||||||
|
|||||||
@@ -102,17 +102,17 @@ abstract class Db extends DbCore
|
|||||||
{
|
{
|
||||||
$end = microtime(true);
|
$end = microtime(true);
|
||||||
|
|
||||||
// Save details
|
$stack = debug_backtrace(false);
|
||||||
$timeSpent = $end - $start;
|
while (preg_match('@[/\\\\]classes[/\\\\]db[/\\\\]@i', $stack[0]['file']))
|
||||||
$trace = debug_backtrace(false);
|
array_shift($stack);
|
||||||
while (preg_match('@[/\\\\]classes[/\\\\]db[/\\\\]@i', $trace[0]['file']))
|
$stack_light = array();
|
||||||
array_shift($trace);
|
foreach ($stack as $call)
|
||||||
|
$stack_light[] = array('file' => $call['file'], 'line' => $call['line']);
|
||||||
|
|
||||||
$this->queries[] = array(
|
$this->queries[] = array(
|
||||||
'query' => $sql,
|
'query' => $sql,
|
||||||
'time' => $timeSpent,
|
'time' => $end - $start,
|
||||||
'file' => $trace[0]['file'],
|
'stack' => $stack_light
|
||||||
'line' => $trace[0]['line'],
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user