cleanPositions query update
We now use an unique query, with no need to use temporary table. Thanks to @sylwit for the tip !
This commit is contained in:
1 parent
0882c187fc
commit
56d4c8339a
1 file changed
+6
-22
+6
-22
@@ -314,29 +314,13 @@ class FeatureCore extends ObjectModel
|
|||||||
{
|
{
|
||||||
$return = true;
|
$return = true;
|
||||||
$sql = '
|
$sql = '
|
||||||
CREATE TEMPORARY TABLE `'._DB_PREFIX_.'feature_tmp` (
|
UPDATE `'._DB_PREFIX_.'feature` f LEFT JOIN
|
||||||
`rank` INT NOT NULL AUTO_INCREMENT,
|
(SELECT @i := @i +1 AS rank, id_feature, position
|
||||||
`id_feature` int not null,
|
FROM `'._DB_PREFIX_.'feature` JOIN (SELECT @i :=1) dummy
|
||||||
`position` int not null,
|
ORDER by position) AS f2
|
||||||
primary key(rank)
|
USING(id_feature)
|
||||||
);
|
SET f.position = f2.rank-1';
|
||||||
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);
|
$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;
|
|
||||||
foreach ($result as $value)
|
|
||||||
$return = Db::getInstance()->execute('
|
|
||||||
UPDATE `'._DB_PREFIX_.'feature`
|
|
||||||
SET `position` = '.(int)$i++.'
|
|
||||||
WHERE `id_feature` = '.(int)$value['id_feature']);
|
|
||||||
}
|
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user