Index: branches/RC/core/units/general/helpers/mod_rewrite_helper.php =================================================================== diff -u -N -r10426 -r10459 --- branches/RC/core/units/general/helpers/mod_rewrite_helper.php (.../mod_rewrite_helper.php) (revision 10426) +++ branches/RC/core/units/general/helpers/mod_rewrite_helper.php (.../mod_rewrite_helper.php) (revision 10459) @@ -245,6 +245,13 @@ function GetItemTemplate($category, $module_prefix) { + $cache_key = serialize($category) . '_' . $module_prefix; + + $cached_value = $this->Application->getCache(__CLASS__ . __FUNCTION__, $cache_key); + if ($cached_value !== false) { + return $cached_value; + } + if (!is_array($category)) { if ($category == 0) { $category = $this->Application->findModule('Var', $module_prefix, 'RootCat'); @@ -257,10 +264,7 @@ $parent_path = implode(',',explode('|', substr($category['ParentPath'], 1, -1))); // item template is stored in module' system custom field - need to get that field Id - $item_template_field_id = $this->Conn->GetOne( - 'SELECT CustomFieldId - FROM '.TABLE_PREFIX.'CustomField - WHERE FieldName = '.$this->Conn->qstr($module_prefix.'_ItemTemplate')); + $item_template_field_id = $this->_getItemTemplateCustomField($module_prefix); // looking for item template through cats hierarchy sorted by parent path $query = 'SELECT ccd.l1_cust_'.$item_template_field_id.', @@ -272,9 +276,29 @@ WHERE c.CategoryId IN ('.$parent_path.') AND ccd.l1_cust_'.$item_template_field_id.' != \'\' ORDER BY FIND_IN_SET(c.CategoryId, '.$this->Conn->qstr($parent_path).') DESC'; $item_template = $this->Conn->GetOne($query); + + $this->Application->setCache(__CLASS__ . __FUNCTION__, $cache_key, $item_template); + return $item_template; } + function _getItemTemplateCustomField($module_prefix) + { + $cached_value = $this->Application->getCache(__CLASS__ . __FUNCTION__, $module_prefix); + if ($cached_value !== false) { + return $cached_value; + } + + $sql = 'SELECT CustomFieldId + FROM '.TABLE_PREFIX.'CustomField + WHERE FieldName = '.$this->Conn->qstr($module_prefix.'_ItemTemplate'); + $item_template_field_id = $this->Conn->GetOne($sql); + + $this->Application->setCache(__CLASS__ . __FUNCTION__, $module_prefix, $item_template_field_id); + + return $item_template_field_id; + } + function ProcessPhisycalTemplate(&$url_parts, &$vars) { if (!isset($url_parts[0])) return false;