Index: branches/RC/core/units/categories/categories_tag_processor.php
===================================================================
diff -u -r10274 -r10459
--- branches/RC/core/units/categories/categories_tag_processor.php (.../categories_tag_processor.php) (revision 10274)
+++ branches/RC/core/units/categories/categories_tag_processor.php (.../categories_tag_processor.php) (revision 10459)
@@ -77,13 +77,13 @@
function ItemCount($params)
{
- $cat_object =& $this->getObject($params);
+ $object =& $this->getObject($params);
$ci_table = $this->Application->getUnitOption('l-ci', 'TableName');
$sql = 'SELECT COUNT(*)
- FROM '.$cat_object->TableName.' c
- LEFT JOIN '.$ci_table.' ci ON c.CategoryId=ci.CategoryId
- WHERE c.ParentPath LIKE "'.$cat_object->GetDBField('ParentPath').'%" AND NOT (ci.CategoryId IS NULL)';
+ FROM ' . $object->TableName . ' c
+ LEFT JOIN ' . $ci_table . ' ci ON c.CategoryId = ci.CategoryId
+ WHERE (c.TreeLeft BETWEEN ' . $object->GetDBField('TreeLeft') . ' AND ' . $object->GetDBField('TreeRight') . ') AND NOT (ci.CategoryId IS NULL)';
return $this->Conn->GetOne($sql);
}
Index: branches/RC/core/units/general/helpers/count_helper.php
===================================================================
diff -u -r9002 -r10459
--- branches/RC/core/units/general/helpers/count_helper.php (.../count_helper.php) (revision 9002)
+++ branches/RC/core/units/general/helpers/count_helper.php (.../count_helper.php) (revision 10459)
@@ -223,11 +223,16 @@
*/
function GetPermissionClause($prefix, $table_alias)
{
- $sql = 'SELECT PermissionConfigId
- FROM '.TABLE_PREFIX.'PermissionConfig
- WHERE PermissionName = "'.$this->Application->getUnitOption($prefix, 'PermItemPrefix').'.VIEW"';
- $view_perm = $this->Conn->GetOne($sql);
+ $view_perm = $this->Application->getCache(__CLASS__ . __FUNCTION__, $prefix);
+ if ($view_perm === false) {
+ $sql = 'SELECT PermissionConfigId
+ FROM '.TABLE_PREFIX.'PermissionConfig
+ WHERE PermissionName = "'.$this->Application->getUnitOption($prefix, 'PermItemPrefix').'.VIEW"';
+ $view_perm = $this->Conn->GetOne($sql);
+ $this->Application->setCache(__CLASS__ . __FUNCTION__, $prefix, $view_perm);
+ }
+
$groups = explode(',', $this->Application->RecallVar('UserGroups'));
foreach ($groups as $group) {
$view_filters[] = 'FIND_IN_SET('.$group.', '.$table_alias.'.acl)';
Index: branches/RC/core/units/general/cat_tag_processor.php
===================================================================
diff -u -r10455 -r10459
--- branches/RC/core/units/general/cat_tag_processor.php (.../cat_tag_processor.php) (revision 10455)
+++ branches/RC/core/units/general/cat_tag_processor.php (.../cat_tag_processor.php) (revision 10459)
@@ -402,7 +402,7 @@
$object =& $this->getObject($params);
/* @var $object kDBItem */
- if ($this->Application->ConfigValue('UseFloatRating')) {
+ if (false && $this->Application->ConfigValue('UseFloatRating')) {
$rating = $object->GetDBField('CachedRating');
$float_rating = floor(($rating - floor($rating)) / 0.25) * 0.25;
}
Index: branches/RC/core/units/general/helpers/mod_rewrite_helper.php
===================================================================
diff -u -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;
Index: branches/RC/core/units/general/country_states.php
===================================================================
diff -u -r10098 -r10459
--- branches/RC/core/units/general/country_states.php (.../country_states.php) (revision 10098)
+++ branches/RC/core/units/general/country_states.php (.../country_states.php) (revision 10459)
@@ -18,26 +18,34 @@
*/
function PopulateStates(&$event, $state_field, $country_field)
{
+ static $country_states = Array ();
+
$object =& $event->getObject();
$country_abbr = $object->GetDBField($country_field);
- if (!$country_abbr) return;
- $country_id = $this->Conn->GetOne('SELECT DestId FROM '.TABLE_PREFIX.'StdDestinations WHERE DestType=1 AND DestAbbr = '.$this->Conn->qstr($country_abbr));
- if (!$country_id) return;
+ if (!$country_abbr) {
+ return ;
+ }
- $query =
- 'SELECT p.Translation as DestName, sd.DestAbbr
- FROM '.TABLE_PREFIX.'StdDestinations AS sd
- LEFT JOIN '.TABLE_PREFIX.'Phrase AS p
- ON p.Phrase = sd.DestName
- WHERE
- DestType=2 AND DestParentId='.$country_id.'
- AND
- LanguageId = '.$this->Application->GetVar('m_lang').'
- ORDER BY Translation';
+ if (!array_key_exists($country_abbr, $country_states)) {
+ $sql = 'SELECT DestId
+ FROM '.TABLE_PREFIX.'StdDestinations
+ WHERE DestType = 1 AND DestAbbr = '.$this->Conn->qstr($country_abbr);
+ $country_id = $this->Conn->GetOne($sql);
+ if (!$country_id) {
+ return ;
+ }
- $states = $this->Conn->GetCol($query, 'DestAbbr');
- $object->Fields[$state_field]['options'] = $states;
+ $sql = 'SELECT p.Translation as DestName, sd.DestAbbr
+ FROM ' . TABLE_PREFIX . 'StdDestinations AS sd
+ LEFT JOIN ' . TABLE_PREFIX . 'Phrase AS p ON p.Phrase = sd.DestName
+ WHERE DestType = 2 AND DestParentId = ' . $country_id . ' AND LanguageId = ' . $this->Application->GetVar('m_lang') . '
+ ORDER BY Translation';
+
+ $country_states[$country_abbr] = $this->Conn->GetCol($sql, 'DestAbbr');
+ }
+
+ $object->Fields[$state_field]['options'] = $country_states[$country_abbr];
$object->Fields[$state_field]['options'][''] = '';
}
Index: branches/RC/core/kernel/db/db_connection.php
===================================================================
diff -u -r9205 -r10459
--- branches/RC/core/kernel/db/db_connection.php (.../db_connection.php) (revision 9205)
+++ branches/RC/core/kernel/db/db_connection.php (.../db_connection.php) (revision 10459)
@@ -79,6 +79,15 @@
var $lastQuery = '';
/**
+ * Total processed queries count
+ *
+ * @var int
+ */
+ var $_queryCount = 0;
+
+// var $_queryLog = Array ();
+
+ /**
* Initializes connection class with
* db type to used in future
*
@@ -336,10 +345,21 @@
* @param string $key_field
* @return Array
*/
- function Query($sql, $key_field = null)
+ function Query($sql, $key_field = null, $no_debug = false)
{
$this->lastQuery = $sql;
- if ($this->debugMode) return $this->debugQuery($sql,$key_field);
+ $this->_queryCount++;
+
+ /*if (!array_key_exists($sql, $this->_queryLog)) {
+ $this->_queryLog[$sql] = 1;
+ }
+ else {
+ $this->_queryLog[$sql]++;
+ }*/
+
+ if ($this->debugMode && !$no_debug) {
+ return $this->debugQuery($sql,$key_field);
+ }
$query_func = $this->getMetaFunction('query');
$this->queryID = $query_func($sql,$this->connectionID);
if (is_resource($this->queryID)) {
@@ -404,7 +424,7 @@
// set 2nd checkpoint: begin
$first_cell = count($ret) == 1 && count(current($ret)) == 1 ? current(current($ret)) : null;
if ($profileSQLs) {
- $debugger->profileFinish('sql_'.$queryID, null, null, $this->getAffectedRows(), $first_cell);
+ $debugger->profileFinish('sql_'.$queryID, null, null, $this->getAffectedRows(), $first_cell, $this->_queryCount);
$debugger->profilerAddTotal('sql', 'sql_'.$queryID);
}
$this->Destroy();
@@ -414,7 +434,7 @@
else {
// set 2nd checkpoint: begin
if ($profileSQLs) {
- $debugger->profileFinish('sql_'.$queryID, null, null, $this->getAffectedRows());
+ $debugger->profileFinish('sql_'.$queryID, null, null, $this->getAffectedRows(), null, $this->_queryCount);
$debugger->profilerAddTotal('sql', 'sql_'.$queryID);
}
// set 2nd checkpoint: end
Index: branches/RC/core/kernel/utility/debugger/debugger.css
===================================================================
diff -u -r8929 -r10459
--- branches/RC/core/kernel/utility/debugger/debugger.css (.../debugger.css) (revision 8929)
+++ branches/RC/core/kernel/utility/debugger/debugger.css (.../debugger.css) (revision 10459)
@@ -7,12 +7,22 @@
display: inline;
}
-.dbg_flat_table, .dbg_stats_table {
+.dbg_flat_table, .dbg_stats_table, table.dbg_explain_table {
border-collapse: collapse;
width: auto;
margin: 0px;
}
+table.dbg_explain_table TD {
+ border: 1px solid #000000;
+ padding: 4px;
+}
+
+table.dbg_explain_table tr.explain_header TD {
+ font-weight: bold;
+ text-align: center;
+}
+
.dbg_flat_table TD, .dbg_stats_table TD {
border: 1px solid #CCCCCC;
padding: 4px;
Index: branches/RC/core/units/general/cat_event_handler.php
===================================================================
diff -u -r10396 -r10459
--- branches/RC/core/units/general/cat_event_handler.php (.../cat_event_handler.php) (revision 10396)
+++ branches/RC/core/units/general/cat_event_handler.php (.../cat_event_handler.php) (revision 10459)
@@ -775,16 +775,18 @@
}
// linking existing images for item with virtual fields
- $image_helper =& $this->Application->recallObject('ImageHelper');
- /* @var $image_helper ImageHelper */
+ if ($event->Prefix != 'cms') {
+ $image_helper =& $this->Application->recallObject('ImageHelper');
+ /* @var $image_helper ImageHelper */
- $image_helper->LoadItemImages($object);
+ $image_helper->LoadItemImages($object);
- // linking existing files for item with virtual fields
- $file_helper =& $this->Application->recallObject('FileHelper');
- /* @var $file_helper FileHelper */
+ // linking existing files for item with virtual fields
+ $file_helper =& $this->Application->recallObject('FileHelper');
+ /* @var $file_helper FileHelper */
- $file_helper->LoadItemFiles($object);
+ $file_helper->LoadItemFiles($object);
+ }
// set item's additional categories to virtual field (used in editing)
$item_categories = $this->getItemCategories($object->GetDBField('ResourceId'));
@@ -800,21 +802,23 @@
}
if (!$this->Application->IsAdmin()) {
- $image_helper =& $this->Application->recallObject('ImageHelper');
- /* @var $image_helper ImageHelper */
-
$object =& $event->getObject();
/* @var $object kDBItem */
- // process image upload in virtual fields
- $image_helper->SaveItemImages($object);
+ if ($event->Prefix != 'cms') {
+ $image_helper =& $this->Application->recallObject('ImageHelper');
+ /* @var $image_helper ImageHelper */
- $file_helper =& $this->Application->recallObject('FileHelper');
- /* @var $file_helper FileHelper */
+ // process image upload in virtual fields
+ $image_helper->SaveItemImages($object);
- // process file upload in virtual fields
- $file_helper->SaveItemFiles($object);
+ $file_helper =& $this->Application->recallObject('FileHelper');
+ /* @var $file_helper FileHelper */
+ // process file upload in virtual fields
+ $file_helper->SaveItemFiles($object);
+ }
+
if ($event->Special != '-item') {
// don't touch categories during cloning
$this->processAdditionalCategories($object, 'update');
@@ -834,21 +838,23 @@
}
if (!$this->Application->IsAdmin()) {
- $image_helper =& $this->Application->recallObject('ImageHelper');
- /* @var $image_helper ImageHelper */
-
$object =& $event->getObject();
/* @var $object kDBItem */
- // process image upload in virtual fields
- $image_helper->SaveItemImages($object);
+ if ($event->Prefix != 'cms') {
+ $image_helper =& $this->Application->recallObject('ImageHelper');
+ /* @var $image_helper ImageHelper */
- $file_helper =& $this->Application->recallObject('FileHelper');
- /* @var $file_helper FileHelper */
+ // process image upload in virtual fields
+ $image_helper->SaveItemImages($object);
- // process file upload in virtual fields
- $file_helper->SaveItemFiles($object);
+ $file_helper =& $this->Application->recallObject('FileHelper');
+ /* @var $file_helper FileHelper */
+ // process file upload in virtual fields
+ $file_helper->SaveItemFiles($object);
+ }
+
if ($event->Special != '-item') {
// don't touch categories during cloning
$this->processAdditionalCategories($object, 'create');
@@ -2344,11 +2350,15 @@
*/
function OnAfterConfigRead(&$event)
{
- $file_helper =& $this->Application->recallObject('FileHelper');
- /* @var $file_helper FileHelper */
+ parent::OnAfterConfigRead($event);
- $file_helper->createItemFiles($event->Prefix, true); // create image fields
- $file_helper->createItemFiles($event->Prefix, false); // create file fields
+ if ($event->Prefix != 'cms') {
+ $file_helper =& $this->Application->recallObject('FileHelper');
+ /* @var $file_helper FileHelper */
+
+ $file_helper->createItemFiles($event->Prefix, true); // create image fields
+ $file_helper->createItemFiles($event->Prefix, false); // create file fields
+ }
}
/**
Index: branches/RC/core/kernel/utility/debugger.php
===================================================================
diff -u -r10304 -r10459
--- branches/RC/core/kernel/utility/debugger.php (.../debugger.php) (revision 10304)
+++ branches/RC/core/kernel/utility/debugger.php (.../debugger.php) (revision 10459)
@@ -4,6 +4,14 @@
class Debugger {
/**
+ * Holds reference to global KernelApplication instance
+ *
+ * @access public
+ * @var kApplication
+ */
+ var $Application = null;
+
+ /**
* Set to true if fatal error occured
*
* @var bool
@@ -173,6 +181,11 @@
$dbg_constMap['DBG_SQL_PROFILE'] = 0;
}
+ // when showing explain make shure, that debugger window is large enough
+ if (array_key_exists('DBG_SQL_EXPLAIN', $dbg_constMap) && $dbg_constMap['DBG_SQL_EXPLAIN']) {
+ $dbg_constMap['DBG_WINDOW_WIDTH'] = 1000;
+ }
+
foreach ($dbg_constMap as $dbg_constName => $dbg_constValue) {
$this->safeDefine($dbg_constName, $dbg_constValue);
}
@@ -565,14 +578,35 @@
*/
function formatSQL($sql)
{
- $sql = preg_replace('/(\n|\t| )+/is', ' ', $sql);
- $sql = preg_replace('/(CREATE TABLE|DROP TABLE|SELECT|UPDATE|SET|REPLACE|INSERT|DELETE|VALUES|FROM|LEFT JOIN|INNER JOIN|LIMIT|WHERE|HAVING|GROUP BY|ORDER BY) /is', "\n\t$1 ", $sql);
- return $this->highlightString($sql);
+ $sql = trim( preg_replace('/(\n|\t| )+/is', ' ', $sql) );
+
+ $formatted_sql = preg_replace('/\s(CREATE TABLE|DROP TABLE|SELECT|UPDATE|SET|REPLACE|INSERT|DELETE|VALUES|FROM|LEFT JOIN|INNER JOIN|LIMIT|WHERE|HAVING|GROUP BY|ORDER BY)\s/is', "\n\t$1 ", ' ' . $sql);
+ $formatted_sql = $this->highlightString($formatted_sql);
+
+ if (defined('DBG_SQL_EXPLAIN') && DBG_SQL_EXPLAIN) {
+ if (substr($sql, 0, 6) == 'SELECT') {
+ $formatted_sql .= '
' . 'Explain:
';
+ $explain_result = $this->Application->Conn->Query('EXPLAIN ' . $sql, null, true);
+
+ $explain_table = '';
+ foreach ($explain_result as $explain_row) {
+ if (!$explain_table) {
+ // first row -> draw header
+ $explain_table .= '