[*] CORE : Remove duplicate SQL queries

This commit is contained in:
gRoussac
2013-11-11 13:41:23 +01:00
parent de404706d9
commit a7869a1f06
22 changed files with 507 additions and 322 deletions
+23 -15
View File
@@ -264,13 +264,17 @@ class AddressCore extends ObjectModel
if(!isset($id_address) || empty($id_address)) if(!isset($id_address) || empty($id_address))
return false; return false;
if (!$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow(' $cache_id = __CLASS__.__FUNCTION__.(int)$id_address;
SELECT c.`active` if (!Cache::isStored($cache_id))
FROM `'._DB_PREFIX_.'address` a {
LEFT JOIN `'._DB_PREFIX_.'country` c ON c.`id_country` = a.`id_country` $result = (bool)Db::getInstance(_PS_USE_SQL_SLAVE_)->getvalue('
WHERE a.`id_address` = '.(int)$id_address)) SELECT c.`active`
return false; FROM `'._DB_PREFIX_.'address` a
return ($result['active']); LEFT JOIN `'._DB_PREFIX_.'country` c ON c.`id_country` = a.`id_country`
WHERE a.`id_address` = '.(int)$id_address);
Cache::store($cache_id, $result);
}
return Cache::retrieve($cache_id);
} }
/** /**
@@ -324,12 +328,17 @@ class AddressCore extends ObjectModel
{ {
if (!$id_customer) if (!$id_customer)
return false; return false;
$cache_id = __CLASS__.__FUNCTION__.(int)$id_customer.'-'.(bool)$active;
return Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(' if (!Cache::isStored($cache_id))
SELECT `id_address` {
FROM `'._DB_PREFIX_.'address` $result = (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
WHERE `id_customer` = '.(int)$id_customer.' AND `deleted` = 0'.($active ? ' AND `active` = 1' : '') SELECT `id_address`
); FROM `'._DB_PREFIX_.'address`
WHERE `id_customer` = '.(int)$id_customer.' AND `deleted` = 0'.($active ? ' AND `active` = 1' : '')
);
Cache::store($cache_id, $result);
}
return Cache::retrieve($cache_id);
} }
/** /**
@@ -379,5 +388,4 @@ class AddressCore extends ObjectModel
$query->where('id_warehouse = 0'); $query->where('id_warehouse = 0');
return Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query); return Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query);
} }
} }
+43 -24
View File
@@ -277,17 +277,20 @@ class CarrierCore extends ObjectModel
public function getMaxDeliveryPriceByWeight($id_zone) public function getMaxDeliveryPriceByWeight($id_zone)
{ {
$sql = 'SELECT d.`price` $cache_id = __CLASS__.__FUNCTION__.(int)$this->id.'-'.(int)$id_zone;
FROM `'._DB_PREFIX_.'delivery` d if (!Cache::isStored($cache_id))
INNER JOIN `'._DB_PREFIX_.'range_weight` w ON d.`id_range_weight` = w.`id_range_weight` {
WHERE d.`id_zone` = '.(int)$id_zone.' $sql = 'SELECT d.`price`
AND d.`id_carrier` = '.(int)$this->id.' FROM `'._DB_PREFIX_.'delivery` d
'.Carrier::sqlDeliveryRangeShop('range_weight').' INNER JOIN `'._DB_PREFIX_.'range_weight` w ON d.`id_range_weight` = w.`id_range_weight`
ORDER BY w.`delimiter2` DESC LIMIT 1'; WHERE d.`id_zone` = '.(int)$id_zone.'
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); AND d.`id_carrier` = '.(int)$this->id.'
if (!isset($result[0]['price'])) '.Carrier::sqlDeliveryRangeShop('range_weight').'
return false; ORDER BY w.`delimiter2` DESC';
return $result[0]['price']; $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql);
Cache::store($cache_id, $result);
}
return Cache::retrieve($cache_id);
} }
/** /**
@@ -357,17 +360,20 @@ class CarrierCore extends ObjectModel
public function getMaxDeliveryPriceByPrice($id_zone) public function getMaxDeliveryPriceByPrice($id_zone)
{ {
$sql = 'SELECT d.`price` $cache_id = __CLASS__.__FUNCTION__.(int)$this->id.'-'.(int)$id_zone;
FROM `'._DB_PREFIX_.'delivery` d if (!Cache::isStored($cache_id))
INNER JOIN `'._DB_PREFIX_.'range_price` r ON d.`id_range_price` = r.`id_range_price` {
WHERE d.`id_zone` = '.(int)$id_zone.' $sql = 'SELECT d.`price`
AND d.`id_carrier` = '.(int)$this->id.' FROM `'._DB_PREFIX_.'delivery` d
'.Carrier::sqlDeliveryRangeShop('range_price').' INNER JOIN `'._DB_PREFIX_.'range_price` r ON d.`id_range_price` = r.`id_range_price`
ORDER BY r.`delimiter2` DESC LIMIT 1'; WHERE d.`id_zone` = '.(int)$id_zone.'
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); AND d.`id_carrier` = '.(int)$this->id.'
if (!isset($result[0]['price'])) '.Carrier::sqlDeliveryRangeShop('range_price').'
return false; ORDER BY r.`delimiter2` DESC';
return $result[0]['price']; $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql);
Cache::store($cache_id, $result);
}
return Cache::retrieve($cache_id);
} }
/** /**
@@ -449,7 +455,13 @@ class CarrierCore extends ObjectModel
GROUP BY c.`id_carrier` GROUP BY c.`id_carrier`
ORDER BY c.`position` ASC'; ORDER BY c.`position` ASC';
$carriers = Db::getInstance()->executeS($sql); $cache_id = __CLASS__.__FUNCTION__.md5($sql);
if (!Cache::isStored($cache_id))
{
$carriers = Db::getInstance()->executeS($sql);
Cache::store($cache_id, $carriers);
}
$carriers = Cache::retrieve($cache_id);
if (is_array($carriers) && count($carriers)) if (is_array($carriers) && count($carriers))
{ {
@@ -1199,7 +1211,14 @@ class CarrierCore extends ObjectModel
$query->where('pc.id_product = '.(int)$product->id); $query->where('pc.id_product = '.(int)$product->id);
$query->where('pc.id_shop = '.(int)$id_shop); $query->where('pc.id_shop = '.(int)$id_shop);
$carriers_for_product = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query); $cache_id = __CLASS__.__FUNCTION__.(int)$product->id.'-'.(int)$id_shop;
if (!Cache::isStored($cache_id))
{
$carriers_for_product = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query);
Cache::store($cache_id, $carriers_for_product);
}
$carriers_for_product = Cache::retrieve($cache_id);
$carrier_list = array(); $carrier_list = array();
if (!empty($carriers_for_product)) if (!empty($carriers_for_product))
{ {
+41 -21
View File
@@ -325,7 +325,7 @@ class CartCore extends ObjectModel
if (!CartRule::isFeatureActive() || !$this->id) if (!CartRule::isFeatureActive() || !$this->id)
return array(); return array();
$cache_key = 'Cart::getCartRules'.$this->id.'-'.$filter; $cache_key = __CLASS__.__FUNCTION__.$this->id.'-'.$filter;
if (!Cache::isStored($cache_key)) if (!Cache::isStored($cache_key))
{ {
$result = Db::getInstance()->executeS(' $result = Db::getInstance()->executeS('
@@ -632,14 +632,19 @@ class CartCore extends ObjectModel
if (!isset($row['pai_id_image']) || $row['pai_id_image'] == 0) if (!isset($row['pai_id_image']) || $row['pai_id_image'] == 0)
{ {
$row2 = Db::getInstance()->getRow(' $cache_id = __CLASS__.__FUNCTION__.'-pai_id_image-'.(int)$row['id_product'].'-'.(int)$this->id_lang.'-'.(int)$row['id_shop'];
SELECT image_shop.`id_image` id_image, il.`legend` if (!Cache::isStored($cache_id))
FROM `'._DB_PREFIX_.'image` i {
JOIN `'._DB_PREFIX_.'image_shop` image_shop ON (i.id_image = image_shop.id_image AND image_shop.cover=1 AND image_shop.id_shop='.(int)$row['id_shop'].') $row2 = Db::getInstance()->getRow('
LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (image_shop.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$this->id_lang.') SELECT image_shop.`id_image` id_image, il.`legend`
WHERE i.`id_product` = '.(int)$row['id_product'].' AND image_shop.`cover` = 1' FROM `'._DB_PREFIX_.'image` i
); JOIN `'._DB_PREFIX_.'image_shop` image_shop ON (i.id_image = image_shop.id_image AND image_shop.cover=1 AND image_shop.id_shop='.(int)$row['id_shop'].')
LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (image_shop.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$this->id_lang.')
WHERE i.`id_product` = '.(int)$row['id_product'].' AND image_shop.`cover` = 122'
);
Cache::store($cache_id, $row2);
}
$row2 = Cache::retrieve($cache_id);
if (!$row2) if (!$row2)
$row2 = array('id_image' => false, 'legend' => false); $row2 = array('id_image' => false, 'legend' => false);
else else
@@ -727,7 +732,7 @@ class CartCore extends ObjectModel
* *
* @result integer Products quantity * @result integer Products quantity
*/ */
public function nbProducts() public function nbProducts()
{ {
if (!$this->id) if (!$this->id)
return 0; return 0;
@@ -1094,7 +1099,13 @@ class CartCore extends ObjectModel
*/ */
public function orderExists() public function orderExists()
{ {
return (bool)Db::getInstance()->getValue('SELECT count(*) FROM `'._DB_PREFIX_.'orders` WHERE `id_cart` = '.(int)$this->id); $cache_id = __CLASS__.__FUNCTION__.(int)$this->id;
if (!Cache::isStored($cache_id))
{
$result = (bool)Db::getInstance()->getValue('SELECT count(*) FROM `'._DB_PREFIX_.'orders` WHERE `id_cart` = '.(int)$this->id);
Cache::store($cache_id, $result);
}
return Cache::retrieve($cache_id);
} }
/** /**
@@ -2277,18 +2288,23 @@ class CartCore extends ObjectModel
public function getAddressCollection() public function getAddressCollection()
{ {
$collection = array(); $collection = array();
$result = Db::getInstance()->executeS( $cache_id = 'Cart::getAddressCollection'.(int)$this->id;
'SELECT DISTINCT `id_address_delivery` if (!Cache::isStored($cache_id))
FROM `'._DB_PREFIX_.'cart_product` {
WHERE id_cart = '.(int)$this->id $result = Db::getInstance()->executeS(
); 'SELECT DISTINCT `id_address_delivery`
FROM `'._DB_PREFIX_.'cart_product`
WHERE id_cart = '.(int)$this->id
);
Cache::store($cache_id, $result);
}
$result = Cache::retrieve($cache_id);
$result[] = array('id_address_delivery' => (int)$this->id_address_delivery); $result[] = array('id_address_delivery' => (int)$this->id_address_delivery);
foreach ($result as $row) foreach ($result as $row)
if ((int)$row['id_address_delivery'] != 0) if ((int)$row['id_address_delivery'] != 0)
$collection[(int)$row['id_address_delivery']] = new Address((int)$row['id_address_delivery']); $collection[(int)$row['id_address_delivery']] = new Address((int)$row['id_address_delivery']);
return $collection; return $collection;
} }
@@ -3466,10 +3482,14 @@ class CartCore extends ObjectModel
) )
WHERE `id_cart` = '.(int)$this->id.' WHERE `id_cart` = '.(int)$this->id.'
'.(Configuration::get('PS_ALLOW_MULTISHIPPING') ? ' AND `id_shop` = '.(int)$this->id_shop : ''); '.(Configuration::get('PS_ALLOW_MULTISHIPPING') ? ' AND `id_shop` = '.(int)$this->id_shop : '');
$result = Db::getInstance()->execute($sql); $cache_id = 'Cart::setNoMultishipping'.(int)$this->id.'-'.(int)$this->id_shop;
if ($result) if (!Cache::isStored($cache_id))
$emptyCache = true; {
if ($result = (bool)Db::getInstance()->execute($sql))
$emptyCache = true;
Cache::store($cache_id, $result);
}
if (Customization::isFeatureActive()) if (Customization::isFeatureActive())
Db::getInstance()->execute(' Db::getInstance()->execute('
+74 -48
View File
@@ -666,9 +666,9 @@ class CategoryCore extends ObjectModel
* @param boolean $active return only active categories * @param boolean $active return only active categories
* @return array categories * @return array categories
*/ */
public static function getHomeCategories($id_lang, $active = true) public static function getHomeCategories($id_lang, $active = true, $id_shop = false)
{ {
return self::getChildren(Configuration::get('PS_HOME_CATEGORY'), $id_lang, $active); return self::getChildren(Configuration::get('PS_HOME_CATEGORY'), $id_lang, $active, $id_shop);
} }
public static function getRootCategory($id_lang = null, Shop $shop = null) public static function getRootCategory($id_lang = null, Shop $shop = null)
@@ -704,16 +704,22 @@ class CategoryCore extends ObjectModel
if (!Validate::isBool($active)) if (!Validate::isBool($active))
die(Tools::displayError()); die(Tools::displayError());
$query = 'SELECT c.`id_category`, cl.`name`, cl.`link_rewrite`, category_shop.`id_shop` $cache_id = __CLASS__.__FUNCTION__.(int)$id_parent.'-'.(int)$id_lang.'-'.(bool)$active.'-'.(int)$id_shop;
FROM `'._DB_PREFIX_.'category` c if (!Cache::isStored($cache_id))
LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (c.`id_category` = cl.`id_category`'.Shop::addSqlRestrictionOnLang('cl').') {
'.Shop::addSqlAssociation('category', 'c').' $query = 'SELECT c.`id_category`, cl.`name`, cl.`link_rewrite`, category_shop.`id_shop`
WHERE `id_lang` = '.(int)$id_lang.' FROM `'._DB_PREFIX_.'category` c
AND c.`id_parent` = '.(int)$id_parent.' LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (c.`id_category` = cl.`id_category`'.Shop::addSqlRestrictionOnLang('cl').')
'.($active ? 'AND `active` = 1' : '').' '.Shop::addSqlAssociation('category', 'c').'
GROUP BY c.`id_category` WHERE `id_lang` = '.(int)$id_lang.'
ORDER BY category_shop.`position` ASC'; AND c.`id_parent` = '.(int)$id_parent.'
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query); '.($active ? 'AND `active` = 1' : '').'
GROUP BY c.`id_category`
ORDER BY category_shop.`position` ASC';
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query);
Cache::store($cache_id, $result);
}
return Cache::retrieve($cache_id);
} }
/** /**
@@ -1008,14 +1014,20 @@ class CategoryCore extends ObjectModel
public function getGroups() public function getGroups()
{ {
$groups = array(); $groups = array();
$result = Db::getInstance()->executeS(' $cache_id = __CLASS__.__FUNCTION__.(int)$this->id;
SELECT cg.`id_group` if (!Cache::isStored($cache_id))
FROM '._DB_PREFIX_.'category_group cg {
WHERE cg.`id_category` = '.(int)$this->id $result = Db::getInstance()->executeS('
); SELECT cg.`id_group`
foreach ($result as $group) FROM '._DB_PREFIX_.'category_group cg
$groups[] = $group['id_group']; WHERE cg.`id_category` = '.(int)$this->id
return $groups; );
$groups = array();
foreach ($result as $group)
$groups[] = $group['id_group'];
Cache::store($cache_id, $groups);
}
return Cache::retrieve($cache_id);
} }
public function addGroupsIfNoExist($id_group) public function addGroupsIfNoExist($id_group)
@@ -1036,24 +1048,23 @@ class CategoryCore extends ObjectModel
*/ */
public function checkAccess($id_customer) public function checkAccess($id_customer)
{ {
if (!$id_customer) $cache_id = __CLASS__.__FUNCTION__.(int)$this->id.'-'.$id_customer.(!$id_customer ? '-'.(int)Group::getCurrent()->id : '');
if (!Cache::isStored($cache_id))
{ {
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow(' if (!$id_customer)
$result = (bool)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
SELECT ctg.`id_group` SELECT ctg.`id_group`
FROM '._DB_PREFIX_.'category_group ctg FROM '._DB_PREFIX_.'category_group ctg
WHERE ctg.`id_category` = '.(int)$this->id.' AND ctg.`id_group` = '.(int)Group::getCurrent()->id.' WHERE ctg.`id_category` = '.(int)$this->id.' AND ctg.`id_group` = '.(int)Group::getCurrent()->id);
'); else
} else { $result = (bool)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
SELECT ctg.`id_group` SELECT ctg.`id_group`
FROM '._DB_PREFIX_.'category_group ctg FROM '._DB_PREFIX_.'category_group ctg
INNER JOIN '._DB_PREFIX_.'customer_group cg on (cg.`id_group` = ctg.`id_group` AND cg.`id_customer` = '.(int)$id_customer.') INNER JOIN '._DB_PREFIX_.'customer_group cg on (cg.`id_group` = ctg.`id_group` AND cg.`id_customer` = '.(int)$id_customer.')
WHERE ctg.`id_category` = '.(int)$this->id WHERE ctg.`id_category` = '.(int)$this->id);
); Cache::store($cache_id, $result);
} }
if ($result && isset($result['id_group']) && $result['id_group']) return Cache::retrieve($cache_id);
return true;
return false;
} }
/** /**
@@ -1199,12 +1210,16 @@ class CategoryCore extends ObjectModel
*/ */
public static function getInterval($id) public static function getInterval($id)
{ {
$sql = 'SELECT nleft, nright, level_depth $cache_id = __CLASS__.__FUNCTION__.(int)$id;
FROM '._DB_PREFIX_.'category if (!Cache::isStored($cache_id))
WHERE id_category = '.(int)$id; {
if (!$result = Db::getInstance()->getRow($sql)) $sql = 'SELECT nleft, nright, level_depth
return false; FROM '._DB_PREFIX_.'category
return $result; WHERE id_category = '.(int)$id;
$result = Db::getInstance()->getRow($sql);
Cache::store($cache_id, $result);
}
return Cache::retrieve($cache_id);
} }
/** /**
@@ -1386,11 +1401,17 @@ class CategoryCore extends ObjectModel
public static function getCategoriesWithoutParent() public static function getCategoriesWithoutParent()
{ {
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' $cache_id = __CLASS__.__FUNCTION__.(int)Context::getContext()->language->id;
SELECT DISTINCT c.* if (!Cache::isStored($cache_id))
FROM `'._DB_PREFIX_.'category` c {
LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (c.`id_category` = cl.`id_category` AND cl.`id_lang` = '.(int)Context::getContext()->language->id.') $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
WHERE `level_depth` = 1'); SELECT DISTINCT c.*
FROM `'._DB_PREFIX_.'category` c
LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (c.`id_category` = cl.`id_category` AND cl.`id_lang` = '.(int)Context::getContext()->language->id.')
WHERE `level_depth` = 1');
Cache::store($cache_id, $result);
}
return Cache::retrieve($cache_id);
} }
public function isRootCategoryForAShop() public function isRootCategoryForAShop()
@@ -1409,12 +1430,17 @@ class CategoryCore extends ObjectModel
public static function getTopCategory($id_lang = null) public static function getTopCategory($id_lang = null)
{ {
if (is_null($id_lang)) if (is_null($id_lang))
$id_lang = Context::getContext()->language->id; $id_lang = (int)Context::getContext()->language->id;
$id_category = Db::getInstance()->getValue(' $cache_id = __CLASS__.__FUNCTION__.(int)$id_lang;
SELECT `id_category` if (!Cache::isStored($cache_id))
FROM `'._DB_PREFIX_.'category` {
WHERE `id_parent` = 0'); $id_category = (int)Db::getInstance()->getValue('
return new Category($id_category, $id_lang); SELECT `id_category`
FROM `'._DB_PREFIX_.'category`
WHERE `id_parent` = 0');
Cache::store($cache_id, new Category($id_category, $id_lang));
}
return Cache::retrieve($cache_id);
} }
public function addPosition($position, $id_shop = null) public function addPosition($position, $id_shop = null)
+10 -4
View File
@@ -296,10 +296,16 @@ class CurrencyCore extends ObjectModel
*/ */
public static function getIdByIsoCode($iso_code, $id_shop = 0) public static function getIdByIsoCode($iso_code, $id_shop = 0)
{ {
$query = Currency::getIdByQuery($id_shop); $cache_id = 'Currency::getIdByIsoCode'.pSQL($iso_code).'-'.(int)$id_shop;
$query->where('iso_code = \''.pSQL($iso_code).'\''); if (!Cache::isStored($cache_id))
{
return (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query->build()); $query = Currency::getIdByQuery($id_shop);
$query->where('iso_code = \''.pSQL($iso_code).'\'');
$result = (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query->build());
Cache::store($cache_id, $result);
}
return Cache::retrieve($cache_id);
} }
/** /**
+48 -29
View File
@@ -362,15 +362,18 @@ class CustomerCore extends ObjectModel
{ {
if (!Validate::isUnsignedId($id_customer)) if (!Validate::isUnsignedId($id_customer))
return true; return true;
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow(' $cache_id = __CLASS__.__FUNCTION__.(int)$id_customer;
SELECT `id_customer` if (!Cache::isStored($cache_id))
FROM `'._DB_PREFIX_.'customer` {
WHERE `id_customer` = \''.(int)$id_customer.'\' $result = (bool)!Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
AND active = 1 SELECT `id_customer`
AND `deleted` = 0'); FROM `'._DB_PREFIX_.'customer`
if (isset($result['id_customer'])) WHERE `id_customer` = \''.(int)$id_customer.'\'
return false; AND active = 1
return true; AND `deleted` = 0');
Cache::store($cache_id, $result);
}
return Cache::retrieve($cache_id);
} }
/** /**
@@ -413,7 +416,7 @@ class CustomerCore extends ObjectModel
public static function customerHasAddress($id_customer, $id_address) public static function customerHasAddress($id_customer, $id_address)
{ {
$key = (int)$id_customer.'-'.(int)$id_address; $key = (int)$id_customer.'-'.(int)$id_address;
if (!array_key_exists($id_address, self::$_customerHasAddress)) if (!array_key_exists($key, self::$_customerHasAddress))
{ {
self::$_customerHasAddress[$key] = (bool)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(' self::$_customerHasAddress[$key] = (bool)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
SELECT `id_address` SELECT `id_address`
@@ -439,15 +442,22 @@ class CustomerCore extends ObjectModel
*/ */
public function getAddresses($id_lang) public function getAddresses($id_lang)
{ {
$sql = 'SELECT DISTINCT a.*, cl.`name` AS country, s.name AS state, s.iso_code AS state_iso $share_order = (bool)Context::getContext()->shop->getGroup()->share_order;
FROM `'._DB_PREFIX_.'address` a $cache_id = 'Customer::getAddresses'.(int)$this->id.'-'.(int)$id_lang.'-'.$share_order;
LEFT JOIN `'._DB_PREFIX_.'country` c ON (a.`id_country` = c.`id_country`) if (!Cache::isStored($cache_id))
LEFT JOIN `'._DB_PREFIX_.'country_lang` cl ON (c.`id_country` = cl.`id_country`) {
LEFT JOIN `'._DB_PREFIX_.'state` s ON (s.`id_state` = a.`id_state`) $sql = 'SELECT DISTINCT a.*, cl.`name` AS country, s.name AS state, s.iso_code AS state_iso
'.(Context::getContext()->shop->getGroup()->share_order ? '' : Shop::addSqlAssociation('country', 'c')).' FROM `'._DB_PREFIX_.'address` a
WHERE `id_lang` = '.(int)$id_lang.' AND `id_customer` = '.(int)$this->id.' AND a.`deleted` = 0'; LEFT JOIN `'._DB_PREFIX_.'country` c ON (a.`id_country` = c.`id_country`)
LEFT JOIN `'._DB_PREFIX_.'country_lang` cl ON (c.`id_country` = cl.`id_country`)
LEFT JOIN `'._DB_PREFIX_.'state` s ON (s.`id_state` = a.`id_state`)
'.($share_order ? '' : Shop::addSqlAssociation('country', 'c')).'
WHERE `id_lang` = '.(int)$id_lang.' AND `id_customer` = '.(int)$this->id.' AND a.`deleted` = 0';
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
Cache::store($cache_id, $result);
}
return Cache::retrieve($cache_id);
} }
/** /**
@@ -476,12 +486,17 @@ class CustomerCore extends ObjectModel
{ {
if (!Validate::isUnsignedId($id_customer) || !Validate::isMd5($passwd)) if (!Validate::isUnsignedId($id_customer) || !Validate::isMd5($passwd))
die (Tools::displayError()); die (Tools::displayError());
$cache_id = 'Customer::checkPassword'.(int)$id_customer.'-'.$passwd;
$sql = 'SELECT `id_customer` if (!Cache::isStored($cache_id))
FROM `'._DB_PREFIX_.'customer` {
WHERE `id_customer` = '.$id_customer.' $sql = 'SELECT `id_customer`
FROM `'._DB_PREFIX_.'customer`
WHERE `id_customer` = '.$id_customer.'
AND `passwd` = \''.$passwd.'\''; AND `passwd` = \''.$passwd.'\'';
return (bool)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql); $result = (bool)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql);
Cache::store($cache_id, $result);
}
return Cache::retrieve($cache_id);
} }
/** /**
@@ -574,12 +589,16 @@ class CustomerCore extends ObjectModel
public static function customerIdExistsStatic($id_customer) public static function customerIdExistsStatic($id_customer)
{ {
$row = Db::getInstance()->getRow(' $cache_id = 'Customer::customerIdExistsStatic'.(int)$id_customer;
SELECT `id_customer` if (!Cache::isStored($cache_id))
FROM '._DB_PREFIX_.'customer c {
WHERE c.`id_customer` = '.(int)$id_customer); $result = (int)Db::getInstance()->getValue('
SELECT `id_customer`
return isset($row['id_customer']); FROM '._DB_PREFIX_.'customer c
WHERE c.`id_customer` = '.(int)$id_customer);
Cache::store($cache_id, $result);
}
return Cache::retrieve($cache_id);
} }
/** /**
+22 -15
View File
@@ -277,24 +277,31 @@ class MetaCore extends ObjectModel
FROM `'._DB_PREFIX_.'category_lang` cl FROM `'._DB_PREFIX_.'category_lang` cl
WHERE cl.`id_lang` = '.(int)$id_lang.' WHERE cl.`id_lang` = '.(int)$id_lang.'
AND cl.`id_category` = '.(int)$id_category.Shop::addSqlRestrictionOnLang('cl'); AND cl.`id_category` = '.(int)$id_category.Shop::addSqlRestrictionOnLang('cl');
if ($row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql))
$cache_id = 'Meta::getCategoryMetas'.(int)$id_category.'-'.(int)$id_lang;
if (!Cache::isStored($cache_id))
{ {
if (empty($row['meta_description'])) if ($row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql))
$row['meta_description'] = strip_tags($row['description']); {
if (empty($row['meta_description']))
// Paginate title $row['meta_description'] = strip_tags($row['description']);
if (!empty($row['meta_title']))
$row['meta_title'] = $title.$row['meta_title'].(!empty($page_number) ? ' ('.$page_number.')' : '').' - '.Configuration::get('PS_SHOP_NAME'); // Paginate title
if (!empty($row['meta_title']))
$row['meta_title'] = $title.$row['meta_title'].(!empty($page_number) ? ' ('.$page_number.')' : '').' - '.Configuration::get('PS_SHOP_NAME');
else
$row['meta_title'] = $row['name'].(!empty($page_number) ? ' ('.$page_number.')' : '').' - '.Configuration::get('PS_SHOP_NAME');
if (!empty($title))
$row['meta_title'] = $title.(!empty($page_number) ? ' ('.$page_number.')' : '').' - '.Configuration::get('PS_SHOP_NAME');
$result = Meta::completeMetaTags($row, $row['name']);
}
else else
$row['meta_title'] = $row['name'].(!empty($page_number) ? ' ('.$page_number.')' : '').' - '.Configuration::get('PS_SHOP_NAME'); $result = Meta::getHomeMetas($id_lang, $page_name);
Cache::store($cache_id, $result);
if (!empty($title))
$row['meta_title'] = $title.(!empty($page_number) ? ' ('.$page_number.')' : '').' - '.Configuration::get('PS_SHOP_NAME');
return Meta::completeMetaTags($row, $row['name']);
} }
return Cache::retrieve($cache_id);
return Meta::getHomeMetas($id_lang, $page_name);
} }
/** /**
+1 -1
View File
@@ -191,7 +191,7 @@ abstract class ObjectModelCore
if ($id) if ($id)
{ {
// Load object from database if object id is present // Load object from database if object id is present
$cache_id = 'objectmodel_'.$this->def['classname'].'_'.(int)$id.'_'.(int)$id_shop.'_'.(int)$id_lang; $cache_id = 'objectmodel_'.$this->def['classname'].'_'.(int)$id.'_'.(int)$this->id_shop.'_'.(int)$id_lang;
if (!Cache::isStored($cache_id)) if (!Cache::isStored($cache_id))
{ {
$sql = new DbQuery(); $sql = new DbQuery();
+64 -56
View File
@@ -229,7 +229,13 @@ class ProductCore extends ObjectModel
protected static $_prices = array(); protected static $_prices = array();
protected static $_pricesLevel2 = array(); protected static $_pricesLevel2 = array();
protected static $_incat = array(); protected static $_incat = array();
/**
* @since 1.5.6.1
* @var array $_cart_quantity is deprecated since 1.5.6.1
*/
protected static $_cart_quantity = array(); protected static $_cart_quantity = array();
protected static $_tax_rules_group = array(); protected static $_tax_rules_group = array();
protected static $_cacheFeatures = array(); protected static $_cacheFeatures = array();
protected static $_frontFeaturesCache = array(); protected static $_frontFeaturesCache = array();
@@ -2434,13 +2440,18 @@ class ProductCore extends ObjectModel
{ {
if (!$context) if (!$context)
$context = Context::getContext(); $context = Context::getContext();
$cache_id = __CLASS__.__FUNCTION__.(int)$id_product.'-'.(int)$context->shop->id;
$sql = 'SELECT image_shop.`id_image` if (!Cache::isStored($cache_id))
FROM `'._DB_PREFIX_.'image` i {
'.Shop::addSqlAssociation('image', 'i').' $sql = 'SELECT image_shop.`id_image`
WHERE i.`id_product` = '.(int)$id_product.' FROM `'._DB_PREFIX_.'image` i
AND image_shop.`cover` = 1'; '.Shop::addSqlAssociation('image', 'i').'
return Db::getInstance()->getRow($sql); WHERE i.`id_product` = '.(int)$id_product.'
AND image_shop.`cover` = 1';
$result = Db::getInstance()->getRow($sql);
Cache::store($cache_id, $result);
}
return Cache::retrieve($cache_id);
} }
/** /**
@@ -2502,15 +2513,17 @@ class ProductCore extends ObjectModel
$cart_quantity = 0; $cart_quantity = 0;
if ((int)$id_cart) if ((int)$id_cart)
{ {
$condition = ''; $cache_id = __CLASS__.__FUNCTION__.(int)$id_product.'-'.(int)$id_cart;
$cache_name = (int)$id_cart.'_'.(int)$id_product; if (!Cache::isStored($cache_id))
if (!isset(self::$_cart_quantity[$cache_name]) || self::$_cart_quantity[$cache_name] != (int)$quantity) {
self::$_cart_quantity[$cache_name] = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(' $sql = 'SELECT SUM(`quantity`)
SELECT SUM(`quantity`)
FROM `'._DB_PREFIX_.'cart_product` FROM `'._DB_PREFIX_.'cart_product`
WHERE `id_product` = '.(int)$id_product.' WHERE `id_product` = '.(int)$id_product.'
AND `id_cart` = '.(int)$id_cart); AND `id_cart` = '.(int)$id_cart;
$cart_quantity = self::$_cart_quantity[$cache_name]; $cart_quantity = (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql);
Cache::store($cache_id, $cart_quantity);
}
$cart_quantity = Cache::retrieve($cache_id);
} }
$id_currency = (int)Validate::isLoadedObject($context->currency) ? $context->currency->id : Configuration::get('PS_CURRENCY_DEFAULT'); $id_currency = (int)Validate::isLoadedObject($context->currency) ? $context->currency->id : Configuration::get('PS_CURRENCY_DEFAULT');
@@ -4300,19 +4313,25 @@ class ProductCore extends ObjectModel
public function checkAccess($id_customer) public function checkAccess($id_customer)
{ {
if (!$id_customer) $cache_id = __CLASS__.__FUNCTION__.(int)$this->id.'-'.(int)$id_customer.(!$id_customer ? '-'.(int)Group::getCurrent()->id : '');
return (bool)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(' if (!Cache::isStored($cache_id))
SELECT ctg.`id_group` {
FROM `'._DB_PREFIX_.'category_product` cp if (!$id_customer)
INNER JOIN `'._DB_PREFIX_.'category_group` ctg ON (ctg.`id_category` = cp.`id_category`) $result = (bool)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
WHERE cp.`id_product` = '.(int)$this->id.' AND ctg.`id_group` ='.(int)Group::getCurrent()->id); SELECT ctg.`id_group`
else FROM `'._DB_PREFIX_.'category_product` cp
return (bool)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(' INNER JOIN `'._DB_PREFIX_.'category_group` ctg ON (ctg.`id_category` = cp.`id_category`)
SELECT cg.`id_group` WHERE cp.`id_product` = '.(int)$this->id.' AND ctg.`id_group` = '.(int)Group::getCurrent()->id);
FROM `'._DB_PREFIX_.'category_product` cp else
INNER JOIN `'._DB_PREFIX_.'category_group` ctg ON (ctg.`id_category` = cp.`id_category`) $result = (bool)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
INNER JOIN `'._DB_PREFIX_.'customer_group` cg ON (cg.`id_group` = ctg.`id_group`) SELECT cg.`id_group`
WHERE cp.`id_product` = '.(int)$this->id.' AND cg.`id_customer` = '.(int)$id_customer); FROM `'._DB_PREFIX_.'category_product` cp
INNER JOIN `'._DB_PREFIX_.'category_group` ctg ON (ctg.`id_category` = cp.`id_category`)
INNER JOIN `'._DB_PREFIX_.'customer_group` cg ON (cg.`id_group` = ctg.`id_group`)
WHERE cp.`id_product` = '.(int)$this->id.' AND cg.`id_customer` = '.(int)$id_customer);
Cache::store($cache_id, $result);
}
return Cache::retrieve($cache_id);
} }
@@ -4872,8 +4891,12 @@ class ProductCore extends ObjectModel
*/ */
public static function getAttributesParams($id_product, $id_product_attribute) public static function getAttributesParams($id_product, $id_product_attribute)
{ {
$id_lang = (int)Context::getContext()->language->id;
$id_shop = (int)Context::getContext()->shop->id;
$cache_id = __CLASS__.__FUNCTION__.(int)$id_product.'-'.(int)$id_product_attribute.'-'.(int)$id_lang.'-'.(int)$id_shop;
// if blocklayered module is installed we check if user has set custom attribute name // if blocklayered module is installed we check if user has set custom attribute name
if (Module::isInstalled('blocklayered')) if (Module::isInstalled('blocklayered') && Module::isEnabled('blocklayered'))
{ {
$nb_custom_values = Db::getInstance()->executeS(' $nb_custom_values = Db::getInstance()->executeS('
SELECT DISTINCT la.`id_attribute`, la.`url_name` as `name` SELECT DISTINCT la.`id_attribute`, la.`url_name` as `name`
@@ -4884,7 +4907,7 @@ class ProductCore extends ObjectModel
ON (pac.`id_product_attribute` = pa.`id_product_attribute`) ON (pac.`id_product_attribute` = pa.`id_product_attribute`)
'.Shop::addSqlAssociation('product_attribute', 'pa').' '.Shop::addSqlAssociation('product_attribute', 'pa').'
LEFT JOIN `'._DB_PREFIX_.'layered_indexable_attribute_lang_value` la LEFT JOIN `'._DB_PREFIX_.'layered_indexable_attribute_lang_value` la
ON (la.`id_attribute` = a.`id_attribute` AND la.`id_lang` = '.(int)Context::getContext()->language->id.') ON (la.`id_attribute` = a.`id_attribute` AND la.`id_lang` = '.(int)$id_lang.')
WHERE la.`url_name` IS NOT NULL AND la.`url_name` != \'\' WHERE la.`url_name` IS NOT NULL AND la.`url_name` != \'\'
AND pa.`id_product` = '.(int)$id_product.' AND pa.`id_product` = '.(int)$id_product.'
AND pac.`id_product_attribute` = '.(int)$id_product_attribute); AND pac.`id_product_attribute` = '.(int)$id_product_attribute);
@@ -4902,7 +4925,7 @@ class ProductCore extends ObjectModel
LEFT JOIN `'._DB_PREFIX_.'attribute` a LEFT JOIN `'._DB_PREFIX_.'attribute` a
ON (a.`id_attribute_group` = g.`id_attribute_group`) ON (a.`id_attribute_group` = g.`id_attribute_group`)
WHERE a.`id_attribute` = '.(int)$attribute['id_attribute'].' WHERE a.`id_attribute` = '.(int)$attribute['id_attribute'].'
AND g.`id_lang` = '.(int)Context::getContext()->language->id.' AND g.`id_lang` = '.(int)$id_lang.'
AND g.`url_name` IS NOT NULL AND g.`url_name` != \'\''); AND g.`url_name` IS NOT NULL AND g.`url_name` != \'\'');
if (empty($group)) if (empty($group))
{ {
@@ -4912,7 +4935,7 @@ class ProductCore extends ObjectModel
LEFT JOIN `'._DB_PREFIX_.'attribute` a LEFT JOIN `'._DB_PREFIX_.'attribute` a
ON (a.`id_attribute_group` = g.`id_attribute_group`) ON (a.`id_attribute_group` = g.`id_attribute_group`)
WHERE a.`id_attribute` = '.(int)$attribute['id_attribute'].' WHERE a.`id_attribute` = '.(int)$attribute['id_attribute'].'
AND g.`id_lang` = '.(int)Context::getContext()->language->id.' AND g.`id_lang` = '.(int)$id_lang.'
AND g.`name` IS NOT NULL'); AND g.`name` IS NOT NULL');
} }
$result[] = array_merge($attribute, $group[0]); $result[] = array_merge($attribute, $group[0]);
@@ -4921,9 +4944,9 @@ class ProductCore extends ObjectModel
SELECT DISTINCT a.`id_attribute_group`, al.`name`, agl.`name` as `group` SELECT DISTINCT a.`id_attribute_group`, al.`name`, agl.`name` as `group`
FROM `'._DB_PREFIX_.'attribute` a FROM `'._DB_PREFIX_.'attribute` a
LEFT JOIN `'._DB_PREFIX_.'attribute_lang` al LEFT JOIN `'._DB_PREFIX_.'attribute_lang` al
ON (a.`id_attribute` = al.`id_attribute` AND al.`id_lang` = '.(int)Context::getContext()->language->id.') ON (a.`id_attribute` = al.`id_attribute` AND al.`id_lang` = '.(int)$id_lang.')
LEFT JOIN `'._DB_PREFIX_.'attribute_group_lang` agl LEFT JOIN `'._DB_PREFIX_.'attribute_group_lang` agl
ON (a.`id_attribute_group` = agl.`id_attribute_group` AND agl.`id_lang` = '.(int)Context::getContext()->language->id.') ON (a.`id_attribute_group` = agl.`id_attribute_group` AND agl.`id_lang` = '.(int)$id_lang.')
LEFT JOIN `'._DB_PREFIX_.'product_attribute_combination` pac LEFT JOIN `'._DB_PREFIX_.'product_attribute_combination` pac
ON (a.`id_attribute` = pac.`id_attribute`) ON (a.`id_attribute` = pac.`id_attribute`)
LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa
@@ -4932,45 +4955,30 @@ class ProductCore extends ObjectModel
WHERE pa.`id_product` = '.(int)$id_product.' WHERE pa.`id_product` = '.(int)$id_product.'
AND pac.id_product_attribute = '.(int)$id_product_attribute.' AND pac.id_product_attribute = '.(int)$id_product_attribute.'
AND a.`id_attribute` NOT IN('.implode(', ', $tab_id_attribute).')'); AND a.`id_attribute` NOT IN('.implode(', ', $tab_id_attribute).')');
$result = array_merge($values_not_custom, $result); return array_merge($values_not_custom, $result);
}
else
{
$result = Db::getInstance()->executeS('
SELECT al.`name`, agl.`name` as `group`
FROM `'._DB_PREFIX_.'attribute` a
LEFT JOIN `'._DB_PREFIX_.'attribute_lang` al
ON (al.`id_attribute` = a.`id_attribute` AND al.`id_lang` = '.(int)Context::getContext()->language->id.')
LEFT JOIN `'._DB_PREFIX_.'product_attribute_combination` pac
ON (pac.`id_attribute` = a.`id_attribute`)
LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa
ON (pa.`id_product_attribute` = pac.`id_product_attribute`)
'.Shop::addSqlAssociation('product_attribute', 'pa').'
LEFT JOIN `'._DB_PREFIX_.'attribute_group_lang` agl
ON (a.`id_attribute_group` = agl.`id_attribute_group` AND agl.`id_lang` = '.(int)Context::getContext()->language->id.')
WHERE pa.`id_product` = '.(int)$id_product.'
AND pac.`id_product_attribute` = '.(int)$id_product_attribute.'
AND agl.`id_lang` = '.(int)Context::getContext()->language->id);
} }
} }
else
if (!Cache::isStored($cache_id))
{ {
$result = Db::getInstance()->executeS(' $result = Db::getInstance()->executeS('
SELECT al.`name`, agl.`name` as `group` SELECT al.`name`, agl.`name` as `group`
FROM `'._DB_PREFIX_.'attribute` a FROM `'._DB_PREFIX_.'attribute` a
LEFT JOIN `'._DB_PREFIX_.'attribute_lang` al LEFT JOIN `'._DB_PREFIX_.'attribute_lang` al
ON (al.`id_attribute` = a.`id_attribute` AND al.`id_lang` = '.(int)Context::getContext()->language->id.') ON (al.`id_attribute` = a.`id_attribute` AND al.`id_lang` = '.(int)$id_lang.')
LEFT JOIN `'._DB_PREFIX_.'product_attribute_combination` pac LEFT JOIN `'._DB_PREFIX_.'product_attribute_combination` pac
ON (pac.`id_attribute` = a.`id_attribute`) ON (pac.`id_attribute` = a.`id_attribute`)
LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa
ON (pa.`id_product_attribute` = pac.`id_product_attribute`) ON (pa.`id_product_attribute` = pac.`id_product_attribute`)
'.Shop::addSqlAssociation('product_attribute', 'pa').' '.Shop::addSqlAssociation('product_attribute', 'pa').'
LEFT JOIN `'._DB_PREFIX_.'attribute_group_lang` agl LEFT JOIN `'._DB_PREFIX_.'attribute_group_lang` agl
ON (a.`id_attribute_group` = agl.`id_attribute_group` AND agl.`id_lang` = '.(int)Context::getContext()->language->id.') ON (a.`id_attribute_group` = agl.`id_attribute_group` AND agl.`id_lang` = '.(int)$id_lang.')
WHERE pa.`id_product` = '.(int)$id_product.' WHERE pa.`id_product` = '.(int)$id_product.'
AND pac.`id_product_attribute` = '.(int)$id_product_attribute.' AND pac.`id_product_attribute` = '.(int)$id_product_attribute.'
AND agl.`id_lang` = '.(int)Context::getContext()->language->id); AND agl.`id_lang` = '.(int)$id_lang);
Cache::store($cache_id, $result);
} }
$result = Cache::retrieve($cache_id);
return $result; return $result;
} }
+26 -14
View File
@@ -80,13 +80,19 @@ class StateCore extends ObjectModel
*/ */
public static function getNameById($id_state) public static function getNameById($id_state)
{ {
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow(' if (!$id_state)
SELECT `name` return false;
FROM `'._DB_PREFIX_.'state` $cache_id = __CLASS__.__FUNCTION__.(int)$id_state;
WHERE `id_state` = '.(int)$id_state if (!Cache::isStored($cache_id))
); {
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
return $result['name']; SELECT `name`
FROM `'._DB_PREFIX_.'state`
WHERE `id_state` = '.(int)$id_state
);
Cache::store($cache_id, $result);
}
return Cache::retrieve($cache_id);
} }
/** /**
@@ -97,13 +103,19 @@ class StateCore extends ObjectModel
*/ */
public static function getIdByName($state) public static function getIdByName($state)
{ {
$result = Db::getInstance()->getValue(' if (empty($state))
SELECT `id_state` return false;
FROM `'._DB_PREFIX_.'state` $cache_id = __CLASS__.__FUNCTION__.pSQL($state);
WHERE `name` LIKE \''.pSQL($state).'\' if (!Cache::isStored($cache_id))
'); {
$result = (int)Db::getInstance()->getValue('
return (int)$result; SELECT `id_state`
FROM `'._DB_PREFIX_.'state`
WHERE `name` LIKE \''.pSQL($state).'\'
');
Cache::store($cache_id, $result);
}
return Cache::retrieve($cache_id);
} }
/** /**
+14 -8
View File
@@ -190,14 +190,20 @@ class TabCore extends ObjectModel
*/ */
public static function getTab($id_lang, $id_tab) public static function getTab($id_lang, $id_tab)
{ {
/* Tabs selection */ $cache_id = __CLASS__.__FUNCTION__.(int)$id_lang.'-'.(int)$id_tab;
return Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow(' if (!Cache::isStored($cache_id))
SELECT * {
FROM `'._DB_PREFIX_.'tab` t /* Tabs selection */
LEFT JOIN `'._DB_PREFIX_.'tab_lang` tl $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
ON (t.`id_tab` = tl.`id_tab` AND tl.`id_lang` = '.(int)$id_lang.') SELECT *
WHERE t.`id_tab` = '.(int)$id_tab FROM `'._DB_PREFIX_.'tab` t
); LEFT JOIN `'._DB_PREFIX_.'tab_lang` tl
ON (t.`id_tab` = tl.`id_tab` AND tl.`id_lang` = '.(int)$id_lang.')
WHERE t.`id_tab` = '.(int)$id_tab
);
Cache::store($cache_id, $result);
}
return Cache::retrieve($cache_id);
} }
/** /**
+12 -6
View File
@@ -54,12 +54,18 @@ class ZoneCore extends ObjectModel
*/ */
public static function getZones($active = false) public static function getZones($active = false)
{ {
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' $cache_id = __CLASS__.__FUNCTION__.(bool)$active;
SELECT * if (!Cache::isStored($cache_id))
FROM `'._DB_PREFIX_.'zone` {
'.($active ? 'WHERE active = 1' : '').' $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
ORDER BY `name` ASC SELECT *
'); FROM `'._DB_PREFIX_.'zone`
'.($active ? 'WHERE active = 1' : '').'
ORDER BY `name` ASC
');
Cache::store($cache_id, $result);
}
return Cache::retrieve($cache_id);
} }
/** /**
+2 -2
View File
@@ -523,13 +523,13 @@ abstract class DbCore
$this->last_cached = true; $this->last_cached = true;
return $result; return $result;
} }
$this->result = $this->query($sql); $this->result = $this->query($sql);
if (!$this->result) if (!$this->result)
return false; return false;
$this->last_cached = false; $this->last_cached = false;
$result = $this->nextRow($this->result); $result = $this->nextRow($this->result);
if (is_null($result))
$result = false;
if ($use_cache && $this->is_cache_enabled) if ($use_cache && $this->is_cache_enabled)
Cache::getInstance()->setQuery($sql, $result); Cache::getInstance()->setQuery($sql, $result);
return $result; return $result;
+7 -1
View File
@@ -1864,7 +1864,13 @@ abstract class ModuleCore
*/ */
public static function getModuleIdByName($name) public static function getModuleIdByName($name)
{ {
return Db::getInstance()->getValue('SELECT `id_module` FROM `'._DB_PREFIX_.'module` WHERE `name` = "'.pSQL($name).'"'); $cache_id = __CLASS__.__FUNCTION__.pSQL($name);
if (!Cache::isStored($cache_id))
{
$result = (int)Db::getInstance()->getValue('SELECT `id_module` FROM `'._DB_PREFIX_.'module` WHERE `name` = "'.pSQL($name).'"');
Cache::store($cache_id, $result);
}
return Cache::retrieve($cache_id);
} }
/** /**
+12 -6
View File
@@ -112,12 +112,18 @@ class OrderStateCore extends ObjectModel
*/ */
public static function getOrderStates($id_lang) public static function getOrderStates($id_lang)
{ {
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' $cache_id = __CLASS__.__FUNCTION__.(int)$id_lang;
SELECT * if (!Cache::isStored($cache_id))
FROM `'._DB_PREFIX_.'order_state` os {
LEFT JOIN `'._DB_PREFIX_.'order_state_lang` osl ON (os.`id_order_state` = osl.`id_order_state` AND osl.`id_lang` = '.(int)$id_lang.') $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
WHERE deleted = 0 SELECT *
ORDER BY `name` ASC'); FROM `'._DB_PREFIX_.'order_state` os
LEFT JOIN `'._DB_PREFIX_.'order_state_lang` osl ON (os.`id_order_state` = osl.`id_order_state` AND osl.`id_lang` = '.(int)$id_lang.')
WHERE deleted = 0
ORDER BY `name` ASC');
Cache::store($cache_id, $result);
}
return Cache::retrieve($cache_id);
} }
/** /**
+13 -8
View File
@@ -187,14 +187,19 @@ class ShopCore extends ObjectModel
public function setUrl() public function setUrl()
{ {
$row = Db::getInstance()->getRow(' $cache_id = __CLASS__.__FUNCTION__.(int)$this->id;
SELECT su.physical_uri, su.virtual_uri, su.domain, su.domain_ssl, t.id_theme, t.name, t.directory if (!Cache::isStored($cache_id))
FROM '._DB_PREFIX_.'shop s {
LEFT JOIN '._DB_PREFIX_.'shop_url su ON (s.id_shop = su.id_shop) $row = Db::getInstance()->getRow('
LEFT JOIN '._DB_PREFIX_.'theme t ON (t.id_theme = s.id_theme) SELECT su.physical_uri, su.virtual_uri, su.domain, su.domain_ssl, t.id_theme, t.name, t.directory
WHERE s.id_shop = '.(int)$this->id.' FROM '._DB_PREFIX_.'shop s
AND s.active = 1 AND s.deleted = 0 AND su.main = 1'); LEFT JOIN '._DB_PREFIX_.'shop_url su ON (s.id_shop = su.id_shop)
LEFT JOIN '._DB_PREFIX_.'theme t ON (t.id_theme = s.id_theme)
WHERE s.id_shop = '.(int)$this->id.'
AND s.active = 1 AND s.deleted = 0 AND su.main = 1');
Cache::store($cache_id, $row);
}
$row = Cache::retrieve($cache_id);
if (!$row) if (!$row)
return false; return false;
+7 -3
View File
@@ -124,9 +124,13 @@ class TaxRuleCore extends ObjectModel
*/ */
public static function isTaxInUse($id_tax) public static function isTaxInUse($id_tax)
{ {
return Db::getInstance()->getValue(' $cache_id = __CLASS__.__FUNCTION__.(int)$id_tax;
SELECT COUNT(*) FROM `'._DB_PREFIX_.'tax_rule` WHERE `id_tax` = '.(int)$id_tax if (!Cache::isStored($cache_id))
); {
$result = (int)Db::getInstance()->getValue('SELECT COUNT(*) FROM `'._DB_PREFIX_.'tax_rule` WHERE `id_tax` = '.(int)$id_tax);
Cache::store($cache_id, $result);
}
return Cache::retrieve($cache_id);
} }
+1 -1
View File
@@ -548,7 +548,7 @@ class ProductControllerCore extends FrontController
$path = Tools::getPath((int)$this->context->shop->id_category, $this->product->name); $path = Tools::getPath((int)$this->context->shop->id_category, $this->product->name);
$this->context->smarty->assign('path', $path); $this->context->smarty->assign('path', $path);
$this->context->smarty->assign('categories', Category::getHomeCategories($this->context->language->id)); $this->context->smarty->assign('categories', Category::getHomeCategories($this->context->language->id, true, (int)$this->context->shop->id));
$this->context->smarty->assign(array('HOOK_PRODUCT_FOOTER' => Hook::exec('displayFooterProduct', array('product' => $this->product, 'category' => $this->category)))); $this->context->smarty->assign(array('HOOK_PRODUCT_FOOTER' => Hook::exec('displayFooterProduct', array('product' => $this->product, 'category' => $this->category))));
} }
+1 -3
View File
@@ -572,7 +572,7 @@ class Blocktopmenu extends Module
switch (substr($item, 0, strlen($value[1]))) switch (substr($item, 0, strlen($value[1])))
{ {
case 'CAT': case 'CAT':
$this->getCategory((int)$id); $this->getCategory($id, $id_lang, $id_shop);
break; break;
case 'PRD': case 'PRD':
@@ -687,9 +687,7 @@ class Blocktopmenu extends Module
if (isset($children) && count($children)) if (isset($children) && count($children))
foreach ($children as $child) foreach ($children as $child)
{
$this->getCategoryOption((int)$child['id_category'], (int)$id_lang, (int)$child['id_shop']); $this->getCategoryOption((int)$child['id_category'], (int)$id_lang, (int)$child['id_shop']);
}
} }
private function getCategory($id_category, $id_lang = false, $id_shop = false) private function getCategory($id_category, $id_lang = false, $id_shop = false)
+14 -8
View File
@@ -171,6 +171,8 @@ class WishList extends ObjectModel
*/ */
public static function getByIdCustomer($id_customer) public static function getByIdCustomer($id_customer)
{ {
if (!Validate::isUnsignedId($id_customer))
die (Tools::displayError());
if (Shop::getContextShopID()) if (Shop::getContextShopID())
$shop_restriction = 'AND id_shop = '.(int)Shop::getContextShopID(); $shop_restriction = 'AND id_shop = '.(int)Shop::getContextShopID();
elseif (Shop::getContextShopGroupID()) elseif (Shop::getContextShopGroupID())
@@ -178,14 +180,18 @@ class WishList extends ObjectModel
else else
$shop_restriction = ''; $shop_restriction = '';
if (!Validate::isUnsignedId($id_customer)) $cache_id = __CLASS__.__FUNCTION__.(int)$id_customer.'-'.(int)Shop::getContextShopID().'-'.(int)Shop::getContextShopGroupID();
die (Tools::displayError()); if (!Cache::isStored($cache_id))
return (Db::getInstance()->executeS(' {
SELECT w.`id_wishlist`, w.`name`, w.`token`, w.`date_add`, w.`date_upd`, w.`counter` $result = Db::getInstance()->executeS('
FROM `'._DB_PREFIX_.'wishlist` w SELECT w.`id_wishlist`, w.`name`, w.`token`, w.`date_add`, w.`date_upd`, w.`counter`
WHERE `id_customer` = '.(int)($id_customer).' FROM `'._DB_PREFIX_.'wishlist` w
'.$shop_restriction.' WHERE `id_customer` = '.(int)($id_customer).'
ORDER BY w.`name` ASC')); '.$shop_restriction.'
ORDER BY w.`name` ASC');
Cache::store($cache_id, $result);
}
return Cache::retrieve($cache_id);
} }
public static function refreshWishList($id_wishlist) public static function refreshWishList($id_wishlist)
+45 -29
View File
@@ -97,18 +97,24 @@ class ProductComment extends ObjectModel
if ($n != null && $n <= 0) if ($n != null && $n <= 0)
$n = 5; $n = 5;
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' $cache_id = __CLASS__.__FUNCTION__.(int)$id_product.'-'.(int)$p.'-'.(int)$n.'-'.(int)$id_customer.'-'.(bool)$validate;
SELECT pc.`id_product_comment`, if (!Cache::isStored($cache_id))
(SELECT count(*) FROM `'._DB_PREFIX_.'product_comment_usefulness` pcu WHERE pcu.`id_product_comment` = pc.`id_product_comment` AND pcu.`usefulness` = 1) as total_useful, {
(SELECT count(*) FROM `'._DB_PREFIX_.'product_comment_usefulness` pcu WHERE pcu.`id_product_comment` = pc.`id_product_comment`) as total_advice, '. $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
((int)$id_customer ? '(SELECT count(*) FROM `'._DB_PREFIX_.'product_comment_usefulness` pcuc WHERE pcuc.`id_product_comment` = pc.`id_product_comment` AND pcuc.id_customer = '.(int)$id_customer.') as customer_advice, ' : ''). SELECT pc.`id_product_comment`,
((int)$id_customer ? '(SELECT count(*) FROM `'._DB_PREFIX_.'product_comment_report` pcrc WHERE pcrc.`id_product_comment` = pc.`id_product_comment` AND pcrc.id_customer = '.(int)$id_customer.') as customer_report, ' : '').' (SELECT count(*) FROM `'._DB_PREFIX_.'product_comment_usefulness` pcu WHERE pcu.`id_product_comment` = pc.`id_product_comment` AND pcu.`usefulness` = 1) as total_useful,
IF(c.id_customer, CONCAT(c.`firstname`, \' \', LEFT(c.`lastname`, 1)), pc.customer_name) customer_name, pc.`content`, pc.`grade`, pc.`date_add`, pc.title (SELECT count(*) FROM `'._DB_PREFIX_.'product_comment_usefulness` pcu WHERE pcu.`id_product_comment` = pc.`id_product_comment`) as total_advice, '.
FROM `'._DB_PREFIX_.'product_comment` pc ((int)$id_customer ? '(SELECT count(*) FROM `'._DB_PREFIX_.'product_comment_usefulness` pcuc WHERE pcuc.`id_product_comment` = pc.`id_product_comment` AND pcuc.id_customer = '.(int)$id_customer.') as customer_advice, ' : '').
LEFT JOIN `'._DB_PREFIX_.'customer` c ON c.`id_customer` = pc.`id_customer` ((int)$id_customer ? '(SELECT count(*) FROM `'._DB_PREFIX_.'product_comment_report` pcrc WHERE pcrc.`id_product_comment` = pc.`id_product_comment` AND pcrc.id_customer = '.(int)$id_customer.') as customer_report, ' : '').'
WHERE pc.`id_product` = '.(int)($id_product).($validate == '1' ? ' AND pc.`validate` = 1' : '').' IF(c.id_customer, CONCAT(c.`firstname`, \' \', LEFT(c.`lastname`, 1)), pc.customer_name) customer_name, pc.`content`, pc.`grade`, pc.`date_add`, pc.title
ORDER BY pc.`date_add` DESC FROM `'._DB_PREFIX_.'product_comment` pc
'.($n ? 'LIMIT '.(int)(($p - 1) * $n).', '.(int)($n) : '')); LEFT JOIN `'._DB_PREFIX_.'customer` c ON c.`id_customer` = pc.`id_customer`
WHERE pc.`id_product` = '.(int)($id_product).($validate == '1' ? ' AND pc.`validate` = 1' : '').'
ORDER BY pc.`date_add` DESC
'.($n ? 'LIMIT '.(int)(($p - 1) * $n).', '.(int)($n) : ''));
Cache::store($cache_id, $result);
}
return Cache::retrieve($cache_id);
} }
/** /**
@@ -118,18 +124,24 @@ class ProductComment extends ObjectModel
*/ */
public static function getByCustomer($id_product, $id_customer, $get_last = false, $id_guest = false) public static function getByCustomer($id_product, $id_customer, $get_last = false, $id_guest = false)
{ {
$results = Db::getInstance()->executeS(' $cache_id = __CLASS__.__FUNCTION__.(int)$id_product.'-'.(int)$id_customer.'-'.(bool)$get_last.'-'.(int)$id_guest;
SELECT * if (!Cache::isStored($cache_id))
FROM `'._DB_PREFIX_.'product_comment` pc {
WHERE pc.`id_product` = '.(int)$id_product.' $results = Db::getInstance()->executeS('
AND '.(!$id_guest ? 'pc.`id_customer` = '.(int)$id_customer : 'pc.`id_guest` = '.(int)$id_guest).' SELECT *
ORDER BY pc.`date_add` DESC ' FROM `'._DB_PREFIX_.'product_comment` pc
.($get_last ? 'LIMIT 1' : '') WHERE pc.`id_product` = '.(int)$id_product.'
); AND '.(!$id_guest ? 'pc.`id_customer` = '.(int)$id_customer : 'pc.`id_guest` = '.(int)$id_guest).'
ORDER BY pc.`date_add` DESC '
.($get_last ? 'LIMIT 1' : '')
);
if ($get_last) if ($get_last && count($results))
$results = array_shift($results); $results = array_shift($results);
return $results;
Cache::store($cache_id, $results);
}
return Cache::retrieve($cache_id);
} }
/** /**
@@ -202,12 +214,16 @@ class ProductComment extends ObjectModel
if (!Validate::isUnsignedId($id_product)) if (!Validate::isUnsignedId($id_product))
die(Tools::displayError()); die(Tools::displayError());
$validate = (int)Configuration::get('PRODUCT_COMMENTS_MODERATE'); $validate = (int)Configuration::get('PRODUCT_COMMENTS_MODERATE');
if (($result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow(' $cache_id = __CLASS__.__FUNCTION__.(int)$id_product.'-'.$validate;
SELECT COUNT(`id_product_comment`) AS "nbr" if (!Cache::isStored($cache_id))
FROM `'._DB_PREFIX_.'product_comment` pc {
WHERE `id_product` = '.(int)($id_product).($validate == '1' ? ' AND `validate` = 1' : ''))) === false) $result = (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
return false; SELECT COUNT(`id_product_comment`) AS "nbr"
return (int)($result['nbr']); FROM `'._DB_PREFIX_.'product_comment` pc
WHERE `id_product` = '.(int)($id_product).($validate == '1' ? ' AND `validate` = 1' : ''));
Cache::store($cache_id, $result);
}
return Cache::retrieve($cache_id);
} }
/** /**
@@ -159,26 +159,33 @@ class ProductCommentCriterion extends ObjectModel
$table = '_shop'; $table = '_shop';
$alias = 'ps'; $alias = 'ps';
} }
return Db::getInstance()->executeS('
SELECT pcc.`id_product_comment_criterion`, pccl.`name` $cache_id = __CLASS__.__FUNCTION__.(int)$id_product.'-'.(int)$id_lang;
FROM `'._DB_PREFIX_.'product_comment_criterion` pcc if (!Cache::isStored($cache_id))
LEFT JOIN `'._DB_PREFIX_.'product_comment_criterion_lang` pccl {
ON (pcc.id_product_comment_criterion = pccl.id_product_comment_criterion) $result = Db::getInstance()->executeS('
LEFT JOIN `'._DB_PREFIX_.'product_comment_criterion_product` pccp SELECT pcc.`id_product_comment_criterion`, pccl.`name`
ON (pcc.`id_product_comment_criterion` = pccp.`id_product_comment_criterion` AND pccp.`id_product` = '.(int)$id_product.') FROM `'._DB_PREFIX_.'product_comment_criterion` pcc
LEFT JOIN `'._DB_PREFIX_.'product_comment_criterion_category` pccc LEFT JOIN `'._DB_PREFIX_.'product_comment_criterion_lang` pccl
ON (pcc.`id_product_comment_criterion` = pccc.`id_product_comment_criterion`) ON (pcc.id_product_comment_criterion = pccl.id_product_comment_criterion)
LEFT JOIN `'._DB_PREFIX_.'product'.$table.'` '.$alias.' LEFT JOIN `'._DB_PREFIX_.'product_comment_criterion_product` pccp
ON ('.$alias.'.id_category_default = pccc.id_category AND '.$alias.'.id_product = '.(int)$id_product.') ON (pcc.`id_product_comment_criterion` = pccp.`id_product_comment_criterion` AND pccp.`id_product` = '.(int)$id_product.')
WHERE pccl.`id_lang` = '.(int)($id_lang).' LEFT JOIN `'._DB_PREFIX_.'product_comment_criterion_category` pccc
AND ( ON (pcc.`id_product_comment_criterion` = pccc.`id_product_comment_criterion`)
pccp.id_product IS NOT NULL LEFT JOIN `'._DB_PREFIX_.'product'.$table.'` '.$alias.'
OR ps.id_product IS NOT NULL ON ('.$alias.'.id_category_default = pccc.id_category AND '.$alias.'.id_product = '.(int)$id_product.')
OR pcc.id_product_comment_criterion_type = 1 WHERE pccl.`id_lang` = '.(int)($id_lang).'
) AND (
AND pcc.active = 1 pccp.id_product IS NOT NULL
GROUP BY pcc.id_product_comment_criterion OR ps.id_product IS NOT NULL
'); OR pcc.id_product_comment_criterion_type = 1
)
AND pcc.active = 1
GROUP BY pcc.id_product_comment_criterion
');
Cache::store($cache_id, $result);
}
return Cache::retrieve($cache_id);
} }
/** /**