[*] FO : Cache on getDiscountsCustomer, follow up https://github.com/PrestaShop/PrestaShop/pull/960

This commit is contained in:
gRoussac
2013-11-11 14:02:11 +01:00
parent a7869a1f06
commit e2d8a33a81
2 changed files with 21 additions and 11 deletions

View File

@@ -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()

View File

@@ -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);
}
/**