Index: branches/5.1.x/units/currencies/currency_rates.php =================================================================== diff -u -N -r13100 -r13164 --- branches/5.1.x/units/currencies/currency_rates.php (.../currency_rates.php) (revision 13100) +++ branches/5.1.x/units/currencies/currency_rates.php (.../currency_rates.php) (revision 13164) @@ -1,6 +1,6 @@ Application =& kApplication::Instance(); + parent::kBase(); + $this->GetRatesData(); } function GetRatesData() { - // written :) just check that it's correct - $conn =& $this->Application->GetADODBConnection(); - $table = $this->Application->getUnitOption('curr', 'TableName'); - $primary = $this->GetPrimaryCurrency(); - $sql = 'SELECT "'.$primary.'" AS TARGET, ISO AS ID, RateToPrimary As RATE, 1 AS UNITS FROM '.$table.' WHERE 1'; - $rates = $conn->Query($sql); - foreach ($rates as $a_rate) { - $this->SetRate($primary, $a_rate['ID'], $a_rate['RATE']); + $cache_key = 'currency_rates[%CurrSerial%]'; + $rates = $this->Application->getCache($cache_key); + $primary = $this->Application->GetPrimaryCurrency(); + + if ($rates === false) { + $conn =& $this->Application->GetADODBConnection(); + + $conn->nextQueryCachable = true; + $sql = 'SELECT ISO, RateToPrimary + FROM ' . $this->Application->getUnitOption('curr', 'TableName') . ' + WHERE Status = ' . STATUS_ACTIVE; + $rates = $conn->Query($sql); + + $this->Application->setCache($cache_key, $rates); } + + foreach ($rates as $rate) { + $this->SetRate($primary, $rate['ISO'], $rate['RateToPrimary']); + } } function GetRate($source_cur, $target_cur, $units = 1) { - $source_cur = ($source_cur == 'PRIMARY') ? $this->GetPrimaryCurrency() : $source_cur; - $target_cur = ($target_cur == 'PRIMARY') ? $this->GetPrimaryCurrency() : $target_cur; + $source_cur = ($source_cur == 'PRIMARY') ? $this->Application->GetPrimaryCurrency() : $source_cur; + $target_cur = ($target_cur == 'PRIMARY') ? $this->Application->GetPrimaryCurrency() : $target_cur; if($source_cur == $target_cur) { return 1; @@ -76,18 +86,6 @@ $this->ExchangeRates[$target_cur]['UNITS'] = $units; } - function GetPrimaryCurrency() - { - if(!$this->PrimaryCurrency) - { - $conn =& $this->Application->GetADODBConnection(); - $table = $this->Application->getUnitOption('curr', 'TableName'); - $sql = 'SELECT ISO FROM '.$table.' WHERE IsPrimary = 1'; - $this->PrimaryCurrency = $conn->GetOne($sql); - } - return $this->PrimaryCurrency; - } - function StoreRates($currencies=null) { $curr_object =& $this->Application->recallObject('curr', null, Array ('skip_autoload' => true)); @@ -127,7 +125,6 @@ function GetRatesData() { - $this->GetPrimaryCurrency(); $xml_parser = xml_parser_create(); $curl_helper =& $this->Application->recallObject('CurlHelper'); @@ -179,7 +176,6 @@ function GetRatesData() { - $this->GetPrimaryCurrency(); $xml_parser = xml_parser_create(); $curl_helper =& $this->Application->recallObject('CurlHelper'); @@ -225,7 +221,6 @@ $curl_helper =& $this->Application->recallObject('CurlHelper'); /* @var $curl_helper kCurlHelper */ - $this->GetPrimaryCurrency(); for($i = 0; $i < 10; $i++) { $time = adodb_mktime() - $i * 3600 * 24; Index: branches/5.1.x/units/products/products_item.php =================================================================== diff -u -N -r13100 -r13164 --- branches/5.1.x/units/products/products_item.php (.../products_item.php) (revision 13100) +++ branches/5.1.x/units/products/products_item.php (.../products_item.php) (revision 13164) @@ -1,6 +1,6 @@ Application->isAdminUser) { - $user_id = $this->Application->RecallVar('user_id'); - $primary_group = $user_id != -2 ? $this->Conn->GetOne('SELECT GroupId FROM '.TABLE_PREFIX.'UserGroup WHERE PrimaryGroup = 1 AND PortalUserId = '.$user_id) : false; + // product + pricing based + $cache_key = 'product_primary_pricing[%PIDSerial:' . $this->GetID() . '%][%PrIDSerial:ProductId:' . $this->GetID() . '%]'; - if ($primary_group) { + if (!$this->Application->isAdmin && $this->Application->LoggedIn()) { + // also group based + $primary_group = (int)$this->Application->Session->GetField('GroupId'); + $cache_key .= ':group=' . $primary_group; + } + + $price_info = $this->Application->getCache($cache_key); + + if ($price_info === false) { + if (!$this->Application->isAdmin && $this->Application->LoggedIn()) { + // logged in user on front-end + $this->Conn->nextQueryCachable = true; $sql = 'SELECT Price, Cost - FROM '.TABLE_PREFIX.'ProductsPricing - WHERE (ProductId = '.$this->GetID().') AND (GroupId = '.$primary_group.') - ORDER BY MinQty'; - $a_values = $this->Conn->GetRow($sql); + FROM ' . TABLE_PREFIX . 'ProductsPricing + WHERE (ProductId = ' . $this->GetID() . ') AND (GroupId = ' . $primary_group . ') + ORDER BY MinQty'; + $price_info = $this->Conn->GetRow($sql); - if ($a_values !== false) { - return $a_values; + if ($price_info !== false) { + $this->Application->setCache($cache_key, $price_info); + + return $price_info; } } - } - $pr_table = $this->Application->getUnitOption('pr', 'TableName'); + // not logged-in user on front-end or in administrative console + $pr_table = $this->Application->getUnitOption('pr', 'TableName'); - if ($this->mode == 't') { - $pr_table = $this->Application->GetTempName($pr_table, 'prefix:'.$this->Prefix); - } + if ($this->IsTempTable()) { + $pr_table = $this->Application->GetTempName($pr_table, 'prefix:' . $this->Prefix); + } - $sql = 'SELECT Price, Cost - FROM '.$pr_table.' - WHERE ('.$this->IDField.' = '.$this->GetID().') AND (IsPrimary = 1)'; + $this->Conn->nextQueryCachable = true; + $sql = 'SELECT Price, Cost + FROM ' . $pr_table . ' + WHERE (' . $this->IDField . ' = ' . $this->GetID() . ') AND (IsPrimary = 1)'; + $price_info = $this->Conn->GetRow($sql); - return $this->Conn->GetRow($sql); + $this->Application->setCache($cache_key, $price_info); + } + + return $price_info; } } \ No newline at end of file Index: branches/5.1.x/units/shipping_quote_engines/shipping_quote_collector.php =================================================================== diff -u -N -r13100 -r13164 --- branches/5.1.x/units/shipping_quote_engines/shipping_quote_collector.php (.../shipping_quote_collector.php) (revision 13100) +++ branches/5.1.x/units/shipping_quote_engines/shipping_quote_collector.php (.../shipping_quote_collector.php) (revision 13164) @@ -1,6 +1,6 @@ Application->GetADODBConnection(); $cached_var_name = 'ShippingQuotes'.crc32(serialize($params)); - $day_ago = adodb_mktime() - 3600*24; - $sql = 'SELECT Data FROM '.TABLE_PREFIX.'Cache WHERE VarName = "'.$cached_var_name.'" - AND Cached > '.$day_ago; - if($shipping_types = $db->GetOne($sql)) - { + + $shipping_types = $this->Application->getDBCache($cached_var_name); + + if ($shipping_types) { return unserialize($shipping_types); } @@ -76,11 +75,8 @@ } $shipping_types = $available_types; - $sql = 'DELETE FROM '.TABLE_PREFIX.'Cache WHERE VarName LIKE "ShippingQuotes%" AND Cached < '.$day_ago; - $db->Query($sql); - $sql = 'INSERT INTO '.TABLE_PREFIX.'Cache(VarName, Data, Cached) - VALUES("'.$cached_var_name.'", '.$db->qstr(serialize($shipping_types)).', '.adodb_mktime().')'; - $db->Query($sql); + $this->Application->setDBCache($cached_var_name, serialize($shipping_types), 24 * 3600); + return $shipping_types; }