Import time improvment
Instead of making as many queries as you ps_feature entries (for each product), it is possible to make it in one query. And we test if the user has the MySQL rights to create temporary tables.
This commit is contained in:
1 parent
cdb9c0cb40
commit
0882c187fc
1 file changed
+22
-11
+22
-11
@@ -313,19 +313,30 @@ class FeatureCore extends ObjectModel
|
|||||||
public static function cleanPositions()
|
public static function cleanPositions()
|
||||||
{
|
{
|
||||||
$return = true;
|
$return = true;
|
||||||
|
|
||||||
$sql = '
|
$sql = '
|
||||||
SELECT `id_feature`
|
CREATE TEMPORARY TABLE `'._DB_PREFIX_.'feature_tmp` (
|
||||||
FROM `'._DB_PREFIX_.'feature`
|
`rank` INT NOT NULL AUTO_INCREMENT,
|
||||||
ORDER BY `position`';
|
`id_feature` int not null,
|
||||||
$result = Db::getInstance()->executeS($sql);
|
`position` int not null,
|
||||||
|
primary key(rank)
|
||||||
|
);
|
||||||
|
INSERT INTO '._DB_PREFIX_.'feature_tmp(id_feature,position) SELECT id_feature,position FROM '._DB_PREFIX_.'feature ORDER BY position ASC;
|
||||||
|
UPDATE `'._DB_PREFIX_.'feature` f LEFT JOIN '._DB_PREFIX_.'feature_tmp t USING(id_feature) SET f.position = rank-1';
|
||||||
|
$return = Db::getInstance()->executeS($sql);
|
||||||
|
if (!$return) {
|
||||||
|
$sql = '
|
||||||
|
SELECT `id_feature`
|
||||||
|
FROM `'._DB_PREFIX_.'feature`
|
||||||
|
ORDER BY `position`';
|
||||||
|
$result = Db::getInstance()->executeS($sql);
|
||||||
|
|
||||||
$i = 0;
|
$i = 0;
|
||||||
foreach ($result as $value)
|
foreach ($result as $value)
|
||||||
$return = Db::getInstance()->execute('
|
$return = Db::getInstance()->execute('
|
||||||
UPDATE `'._DB_PREFIX_.'feature`
|
UPDATE `'._DB_PREFIX_.'feature`
|
||||||
SET `position` = '.(int)$i++.'
|
SET `position` = '.(int)$i++.'
|
||||||
WHERE `id_feature` = '.(int)$value['id_feature']);
|
WHERE `id_feature` = '.(int)$value['id_feature']);
|
||||||
|
}
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user