[*] FO : Cache on getDiscountsCustomer, follow up https://github.com/PrestaShop/PrestaShop/pull/960
This commit is contained in:
@@ -368,12 +368,16 @@ class CartCore extends ObjectModel
|
||||
{
|
||||
if (!CartRule::isFeatureActive())
|
||||
return 0;
|
||||
|
||||
return Db::getInstance()->getValue('
|
||||
SELECT COUNT(*)
|
||||
FROM `'._DB_PREFIX_.'cart_cart_rule`
|
||||
WHERE `id_cart_rule` = '.(int)$id_cart_rule.' AND `id_cart` = '.(int)$this->id
|
||||
);
|
||||
$cache_id = __CLASS__.__FUNCTION__.(int)$this->id.'-'.(int)$id_cart_rule;
|
||||
if (!Cache::isStored($cache_id))
|
||||
{
|
||||
$result = (int)Db::getInstance()->getValue('
|
||||
SELECT COUNT(*)
|
||||
FROM `'._DB_PREFIX_.'cart_cart_rule`
|
||||
WHERE `id_cart_rule` = '.(int)$id_cart_rule.' AND `id_cart` = '.(int)$this->id);
|
||||
Cache::store($cache_id, $result);
|
||||
}
|
||||
return Cache::retrieve($cache_id);
|
||||
}
|
||||
|
||||
public function getLastProduct()
|
||||
|
||||
@@ -721,11 +721,17 @@ class OrderCore extends ObjectModel
|
||||
|
||||
public static function getDiscountsCustomer($id_customer, $id_cart_rule)
|
||||
{
|
||||
return Db::getInstance()->getValue('
|
||||
SELECT COUNT(*) FROM `'._DB_PREFIX_.'orders` o
|
||||
LEFT JOIN '._DB_PREFIX_.'order_cart_rule ocr ON (ocr.id_order = o.id_order)
|
||||
WHERE o.id_customer = '.(int)$id_customer.'
|
||||
AND ocr.id_cart_rule = '.(int)$id_cart_rule);
|
||||
$cache_id = __CLASS__.__FUNCTION__.(int)$id_customer.'-'.(int)$id_cart_rule;
|
||||
if (!Cache::isStored($cache_id))
|
||||
{
|
||||
$result = (int)Db::getInstance()->getValue('
|
||||
SELECT COUNT(*) FROM `'._DB_PREFIX_.'orders` o
|
||||
LEFT JOIN '._DB_PREFIX_.'order_cart_rule ocr ON (ocr.id_order = o.id_order)
|
||||
WHERE o.id_customer = '.(int)$id_customer.'
|
||||
AND ocr.id_cart_rule = '.(int)$id_cart_rule);
|
||||
Cache::store($cache_id, $result);
|
||||
}
|
||||
return Cache::retrieve($cache_id);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user