Index: branches/5.1.x/core/units/categories/categories_tag_processor.php =================================================================== diff -u -N -r13159 -r13168 --- branches/5.1.x/core/units/categories/categories_tag_processor.php (.../categories_tag_processor.php) (revision 13159) +++ branches/5.1.x/core/units/categories/categories_tag_processor.php (.../categories_tag_processor.php) (revision 13168) @@ -1,6 +1,6 @@ Application->getCache($cache_key); + + if ($cache === false) { $id_field = $this->Application->getUnitOption($this->Prefix, 'IDField'); $table_name = $this->Application->getUnitOption($this->Prefix, 'TableName'); // get symlinked categories, that are not yet deleted + $this->Conn->nextQueryCachable = true; $sql = 'SELECT c1.SymLinkCategoryId, c1.' . $id_field . ' FROM ' . $table_name . ' c1 JOIN ' . $table_name . ' c2 ON c1.SymLinkCategoryId = c2.' . $id_field; $cache = $this->Conn->GetCol($sql, $id_field); + + $this->Application->setCache($cache_key, $cache); } return array_key_exists($category_id, $cache) ? $cache[$category_id] : $category_id; @@ -748,27 +752,34 @@ */ 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 = '.$category_id; - $tree_info = $this->Conn->GetRow($sql); + $serial_name = $this->Application->incrementCacheSerial('c', $local ? $category_id : null, false); + $cache_key = 'category_last_updated[%' . $serial_name . '%]'; - $sql = 'SELECT MAX(c.Modified) AS ModDate, MAX(c.CreatedOn) AS NewDate - FROM '.TABLE_PREFIX.'Category c - WHERE c.TreeLeft BETWEEN '.$tree_info['TreeLeft'].' AND '.$tree_info['TreeRight']; + $row_data = $this->Application->getCache($cache_key); + + 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(Modified) AS ModDate, MAX(CreatedOn) AS NewDate + FROM ' . TABLE_PREFIX . 'Category + WHERE TreeLeft BETWEEN ' . $tree_left . ' AND ' . $tree_right; + } + else { + // scan all categories in system + $sql = 'SELECT MAX(Modified) AS ModDate, MAX(CreatedOn) AS NewDate + FROM ' . TABLE_PREFIX . 'Category'; + } + + $this->Conn->nextQueryCachable = true; + $row_data = $this->Conn->GetRow($sql); + $this->Application->setCache($cache_key, $row_data); } - else { - // scan all categories in system - $sql = 'SELECT MAX(Modified) AS ModDate, MAX(CreatedOn) AS NewDate - FROM '.$table_name; - } - $row_data = $this->Conn->GetRow($sql); if (!$row_data) { return ''; } @@ -781,7 +792,7 @@ $lang =& $this->Application->recallObject('lang.current'); if ($regs[1] == 'DateTimeFormat') { // combined format - $format = $lang->GetDBField('DateFormat').' '.$lang->GetDBField('TimeFormat'); + $format = $lang->GetDBField('DateFormat') . ' ' . $lang->GetDBField('TimeFormat'); } else { // simple format @@ -891,20 +902,24 @@ } // 1. try to get already cached suggestion - $suggestion = $this->Application->getCache('search.suggestion', $keywords); + $cache_key = 'search.suggestion[%SpellingDictionary%]:' . $keywords; + $suggestion = $this->Application->getCache($cache_key); + if ($suggestion !== false) { return $suggestion; } $table_name = $this->Application->getUnitOption('spelling-dictionary', 'TableName'); // 2. search suggestion in database + $this->Conn->nextQueryCachable = true; $sql = 'SELECT SuggestedCorrection FROM ' . $table_name . ' WHERE MisspelledWord = ' . $this->Conn->qstr($keywords); $suggestion = $this->Conn->GetOne($sql); + if ($suggestion !== false) { - $this->Application->setCache('search.suggestion', $keywords, $suggestion); + $this->Application->setCache($cache_key, $suggestion); return $suggestion; } @@ -933,7 +948,7 @@ ); $this->Conn->doInsert($fields_hash, $table_name); - $this->Application->setCache('search.suggestion', $keywords, $result->Data); + $this->Application->setCache($cache_key, $result->Data); return $result->Data; } @@ -1003,7 +1018,15 @@ $object =& $this->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) { @@ -1035,8 +1058,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; }