Index: branches/5.1.x/core/kernel/db/cat_tag_processor.php =================================================================== diff -u -N -r13159 -r13168 --- branches/5.1.x/core/kernel/db/cat_tag_processor.php (.../cat_tag_processor.php) (revision 13159) +++ branches/5.1.x/core/kernel/db/cat_tag_processor.php (.../cat_tag_processor.php) (revision 13168) @@ -1,6 +1,6 @@ getObject($params); $category_id = isset($params['cat_id']) ? $params['cat_id'] : $object->GetDBField('CategoryId'); - $category_path = $this->Application->getCache('category_paths', $category_id); + $cache_key = 'category_paths[%CIDSerial:' . $category_id . '%]'; + + if ($category_id == 0) { + // home category name is phrase AND phrase name is defined in configuration + $cache_key .= '[%PhrasesSerial%][%ConfSerial%]'; + } + + $category_path = $this->Application->getCache($cache_key); + if ($category_path === false) { // not chached if ($category_id > 0) { @@ -251,8 +259,10 @@ else { $category_path = $this->Application->Phrase( $this->Application->ConfigValue('Root_Name') ); } - $this->Application->setCache('category_paths', $category_id, $category_path); + + $this->Application->setCache($cache_key, $category_path); } + return $category_path; } @@ -336,10 +346,22 @@ function HasAdditionalImages($params) { $object =& $this->getObject($params); - $sql = 'SELECT ImageId - FROM '.$this->Application->getUnitOption('img', 'TableName').' - WHERE ResourceId = '.$object->GetDBField('ResourceId').' AND DefaultImg != 1 AND Enabled = 1'; - return $this->Conn->GetOne($sql) ? 1 : 0; + /* @var $object kDBItem */ + + $cache_key = 'product_additional_images[%PIDSerial:' . $object->GetID() . '%]'; + $ret = $this->Application->getCache($cache_key); + + if ($ret === false) { + $this->Conn->nextQueryCachable = true; + $sql = 'SELECT ImageId + FROM ' . $this->Application->getUnitOption('img', 'TableName') . ' + WHERE ResourceId = ' . $object->GetDBField('ResourceId') . ' AND DefaultImg != 1 AND Enabled = 1'; + $ret = $this->Conn->GetOne($sql) ? 1 : 0; + + $this->Application->setCache($cache_key, $ret); + } + + return $ret; } /** @@ -589,29 +611,37 @@ */ function LastUpdated($params) { - $category_id = $this->Application->GetVar('m_cat_id'); - $table_name = $this->Application->getUnitOption($this->Prefix, 'TableName'); + $category_id = (int)$this->Application->GetVar('m_cat_id'); + $local = array_key_exists('local', $params) && ($category_id > 0) ? $params['local'] : false; - if (isset($params['local']) && $params['local'] && $category_id > 0) { - // scan only current category & it's children - $sql = 'SELECT TreeLeft, TreeRight - FROM ' . TABLE_PREFIX . 'Category - WHERE CategoryId = ' . (int)$category_id; - $tree_info = $this->Conn->GetRow($sql); + $serial_name1 = $this->Application->incrementCacheSerial('c', $local ? $category_id : null, false); + $serial_name2 = $this->Application->incrementCacheSerial($this->Prefix, null, false); + $cache_key = 'categoryitems_last_updated[%' . $serial_name1 . '%][%' . $serial_name2 . '%]'; - $sql = 'SELECT MAX(item_table.Modified) AS ModDate, MAX(item_table.CreatedOn) AS NewDate - FROM '.$table_name.' item_table - LEFT JOIN '.TABLE_PREFIX.'CategoryItems ci ON (item_table.ResourceId = ci.ItemResourceId) - LEFT JOIN '.TABLE_PREFIX.'Category c ON c.CategoryId = ci.CategoryId - WHERE c.TreeLeft BETWEEN '.$tree_info['TreeLeft'].' AND '.$tree_info['TreeRight']; - } - else { - // scan all categories in system - $sql = 'SELECT MAX(Modified) AS ModDate, MAX(CreatedOn) AS NewDate - FROM '.$table_name; - } + $row_data = $this->Application->getCache($cache_key); - $row_data = $this->Conn->GetRow($sql); + if ($row_data === false) { + if ($local && ($category_id > 0)) { + // scan only current category & it's children + list ($tree_left, $tree_right) = $this->Application->getTreeIndex($category_id); + + $sql = 'SELECT MAX(item_table.Modified) AS ModDate, MAX(item_table.CreatedOn) AS NewDate + FROM ' . $this->Application->getUnitOption($this->Prefix, 'TableName') . ' item_table + LEFT JOIN ' . TABLE_PREFIX . 'CategoryItems ci ON (item_table.ResourceId = ci.ItemResourceId) + LEFT JOIN ' . TABLE_PREFIX . 'Category c ON c.CategoryId = ci.CategoryId + WHERE c.TreeLeft BETWEEN ' . $tree_left . ' AND ' . $tree_right; + } + else { + // scan all categories in system + $sql = 'SELECT MAX(Modified) AS ModDate, MAX(CreatedOn) AS NewDate + FROM ' . $this->Application->getUnitOption($this->Prefix, 'TableName'); + } + + $this->Conn->nextQueryCachable = true; + $row_data = $this->Conn->GetRow($sql); + $this->Application->setCache($cache_key, $row_data); + } + if (!$row_data) { return ''; }