Index: branches/RC/core/install/install_schema.sql =================================================================== diff -u -N -r10494 -r10516 --- branches/RC/core/install/install_schema.sql (.../install_schema.sql) (revision 10494) +++ branches/RC/core/install/install_schema.sql (.../install_schema.sql) (revision 10516) @@ -542,6 +542,7 @@ StatisticsId int(10) unsigned NOT NULL auto_increment, TemplateName varchar(255) NOT NULL default '', Hits int(10) unsigned NOT NULL default '0', + LastHit int(11) NOT NULL default '0', ScriptTimeMin decimal(40,20) unsigned NOT NULL default '0.00000000000000000000', ScriptTimeAvg decimal(40,20) unsigned NOT NULL default '0.00000000000000000000', ScriptTimeMax decimal(40,20) unsigned NOT NULL default '0.00000000000000000000', @@ -554,6 +555,7 @@ PRIMARY KEY (StatisticsId), KEY TemplateName (TemplateName), KEY Hits (Hits), + KEY LastHit (LastHit), KEY ScriptTimeMin (ScriptTimeMin), KEY ScriptTimeAvg (ScriptTimeAvg), KEY ScriptTimeMax (ScriptTimeMax), @@ -569,13 +571,15 @@ CaptureId int(10) unsigned NOT NULL auto_increment, TemplateNames text, Hits int(10) unsigned NOT NULL default '0', + LastHit int(11) NOT NULL default '0', SqlQuery text, TimeMin decimal(40,20) unsigned NOT NULL default '0.00000000000000000000', TimeAvg decimal(40,20) unsigned NOT NULL default '0.00000000000000000000', TimeMax decimal(40,20) unsigned NOT NULL default '0.00000000000000000000', QueryCrc int(11) NOT NULL default '0', PRIMARY KEY (CaptureId), KEY Hits (Hits), + KEY LastHit (LastHit), KEY TimeMin (TimeMin), KEY TimeAvg (TimeAvg), KEY TimeMax (TimeMax), Index: branches/RC/core/install/upgrades.sql =================================================================== diff -u -N -r10497 -r10516 --- branches/RC/core/install/upgrades.sql (.../upgrades.sql) (revision 10497) +++ branches/RC/core/install/upgrades.sql (.../upgrades.sql) (revision 10516) @@ -253,6 +253,7 @@ StatisticsId int(10) unsigned NOT NULL auto_increment, TemplateName varchar(255) NOT NULL default '', Hits int(10) unsigned NOT NULL default '0', + LastHit int(11) NOT NULL default '0', ScriptTimeMin decimal(40,20) unsigned NOT NULL default '0.00000000000000000000', ScriptTimeAvg decimal(40,20) unsigned NOT NULL default '0.00000000000000000000', ScriptTimeMax decimal(40,20) unsigned NOT NULL default '0.00000000000000000000', @@ -265,6 +266,7 @@ PRIMARY KEY (StatisticsId), KEY TemplateName (TemplateName), KEY Hits (Hits), + KEY LastHit (LastHit), KEY ScriptTimeMin (ScriptTimeMin), KEY ScriptTimeAvg (ScriptTimeAvg), KEY ScriptTimeMax (ScriptTimeMax), @@ -280,13 +282,15 @@ CaptureId int(10) unsigned NOT NULL auto_increment, TemplateNames text, Hits int(10) unsigned NOT NULL default '0', + LastHit int(11) NOT NULL default '0', SqlQuery text, TimeMin decimal(40,20) unsigned NOT NULL default '0.00000000000000000000', TimeAvg decimal(40,20) unsigned NOT NULL default '0.00000000000000000000', TimeMax decimal(40,20) unsigned NOT NULL default '0.00000000000000000000', QueryCrc int(11) NOT NULL default '0', PRIMARY KEY (CaptureId), KEY Hits (Hits), + KEY LastHit (LastHit), KEY TimeMin (TimeMin), KEY TimeAvg (TimeAvg), KEY TimeMax (TimeMax), Index: branches/RC/core/units/general/cat_event_handler.php =================================================================== diff -u -N -r10459 -r10516 --- branches/RC/core/units/general/cat_event_handler.php (.../cat_event_handler.php) (revision 10459) +++ branches/RC/core/units/general/cat_event_handler.php (.../cat_event_handler.php) (revision 10516) @@ -396,10 +396,7 @@ return false; } - $sql = 'SELECT TreeLeft, TreeRight - FROM '.TABLE_PREFIX.'Category - WHERE CategoryId = '.$category_id; - $tree_indexes = $this->Conn->GetRow($sql); + $tree_indexes = $this->Application->getTreeIndex($category_id); return TABLE_PREFIX.'Category.TreeLeft BETWEEN '.$tree_indexes['TreeLeft'].' AND '.$tree_indexes['TreeRight']; } Index: branches/RC/core/units/categories/categories_event_handler.php =================================================================== diff -u -N -r10428 -r10516 --- branches/RC/core/units/categories/categories_event_handler.php (.../categories_event_handler.php) (revision 10428) +++ branches/RC/core/units/categories/categories_event_handler.php (.../categories_event_handler.php) (revision 10516) @@ -180,10 +180,7 @@ if ($event->getEventParam('recursive')) { if ($parent_cat_id > 0) { // not "Home" category - $sql = 'SELECT TreeLeft, TreeRight - FROM '.TABLE_PREFIX.'Category - WHERE CategoryId = '.$parent_cat_id; - $tree_indexes = $this->Conn->GetRow($sql); + $tree_indexes = $this->Application->getTreeIndex($parent_cat_id); $object->addFilter('parent_filter', TABLE_PREFIX.'Category.TreeLeft BETWEEN '.$tree_indexes['TreeLeft'].' AND '.$tree_indexes['TreeRight']); } Index: branches/RC/admin/install/upgrades/inportal_upgrade_v4.3.1.sql =================================================================== diff -u -N -r10508 -r10516 --- branches/RC/admin/install/upgrades/inportal_upgrade_v4.3.1.sql (.../inportal_upgrade_v4.3.1.sql) (revision 10508) +++ branches/RC/admin/install/upgrades/inportal_upgrade_v4.3.1.sql (.../inportal_upgrade_v4.3.1.sql) (revision 10516) @@ -4,9 +4,9 @@ INSERT INTO ConfigurationAdmin VALUES ('RememberLastAdminTemplate', 'la_Text_General', 'la_config_RememberLastAdminTemplate', 'checkbox', '', '', 10.13, 0, 0); INSERT INTO ConfigurationValues VALUES (DEFAULT, 'RememberLastAdminTemplate', '', 'In-Portal:Users', 'in-portal:configure_users'); -CREATE TABLE StatisticsCapture (StatisticsId int(10) unsigned NOT NULL auto_increment, TemplateName varchar(255) NOT NULL default '', Hits int(10) unsigned NOT NULL default '0', ScriptTimeMin decimal(40,20) unsigned NOT NULL default '0.00000000000000000000', ScriptTimeAvg decimal(40,20) unsigned NOT NULL default '0.00000000000000000000', ScriptTimeMax decimal(40,20) unsigned NOT NULL default '0.00000000000000000000', SqlTimeMin decimal(40,20) unsigned NOT NULL default '0.00000000000000000000', SqlTimeAvg decimal(40,20) unsigned NOT NULL default '0.00000000000000000000', SqlTimeMax decimal(40,20) unsigned NOT NULL default '0.00000000000000000000', SqlCountMin decimal(40,20) unsigned NOT NULL default '0.00000000000000000000', SqlCountAvg decimal(40,20) unsigned NOT NULL default '0.00000000000000000000', SqlCountMax decimal(40,20) unsigned NOT NULL default '0.00000000000000000000', PRIMARY KEY (StatisticsId), KEY TemplateName (TemplateName), KEY Hits (Hits), KEY ScriptTimeMin (ScriptTimeMin), KEY ScriptTimeAvg (ScriptTimeAvg), KEY ScriptTimeMax (ScriptTimeMax), KEY SqlTimeMin (SqlTimeMin), KEY SqlTimeAvg (SqlTimeAvg), KEY SqlTimeMax (SqlTimeMax), KEY SqlCountMin (SqlCountMin), KEY SqlCountAvg (SqlCountAvg), KEY SqlCountMax (SqlCountMax)); +CREATE TABLE StatisticsCapture (StatisticsId int(10) unsigned NOT NULL auto_increment, TemplateName varchar(255) NOT NULL default '', Hits int(10) unsigned NOT NULL default '0', LastHit int(11) NOT NULL default '0', ScriptTimeMin decimal(40,20) unsigned NOT NULL default '0.00000000000000000000', ScriptTimeAvg decimal(40,20) unsigned NOT NULL default '0.00000000000000000000', ScriptTimeMax decimal(40,20) unsigned NOT NULL default '0.00000000000000000000', SqlTimeMin decimal(40,20) unsigned NOT NULL default '0.00000000000000000000', SqlTimeAvg decimal(40,20) unsigned NOT NULL default '0.00000000000000000000', SqlTimeMax decimal(40,20) unsigned NOT NULL default '0.00000000000000000000', SqlCountMin decimal(40,20) unsigned NOT NULL default '0.00000000000000000000', SqlCountAvg decimal(40,20) unsigned NOT NULL default '0.00000000000000000000', SqlCountMax decimal(40,20) unsigned NOT NULL default '0.00000000000000000000', PRIMARY KEY (StatisticsId), KEY TemplateName (TemplateName), KEY Hits (Hits), KEY LastHit (LastHit), KEY ScriptTimeMin (ScriptTimeMin), KEY ScriptTimeAvg (ScriptTimeAvg), KEY ScriptTimeMax (ScriptTimeMax), KEY SqlTimeMin (SqlTimeMin), KEY SqlTimeAvg (SqlTimeAvg), KEY SqlTimeMax (SqlTimeMax), KEY SqlCountMin (SqlCountMin), KEY SqlCountAvg (SqlCountAvg), KEY SqlCountMax (SqlCountMax)); -CREATE TABLE SlowSqlCapture (CaptureId int(10) unsigned NOT NULL auto_increment, TemplateNames text, Hits int(10) unsigned NOT NULL default '0', SqlQuery text, TimeMin decimal(40,20) unsigned NOT NULL default '0.00000000000000000000', TimeAvg decimal(40,20) unsigned NOT NULL default '0.00000000000000000000', TimeMax decimal(40,20) unsigned NOT NULL default '0.00000000000000000000', QueryCrc int(11) NOT NULL default '0', PRIMARY KEY (CaptureId), KEY Hits (Hits), KEY TimeMin (TimeMin), KEY TimeAvg (TimeAvg), KEY TimeMax (TimeMax), KEY QueryCrc (QueryCrc)); +CREATE TABLE SlowSqlCapture (CaptureId int(10) unsigned NOT NULL auto_increment, TemplateNames text, Hits int(10) unsigned NOT NULL default '0', LastHit int(11) NOT NULL default '0', SqlQuery text, TimeMin decimal(40,20) unsigned NOT NULL default '0.00000000000000000000', TimeAvg decimal(40,20) unsigned NOT NULL default '0.00000000000000000000', TimeMax decimal(40,20) unsigned NOT NULL default '0.00000000000000000000', QueryCrc int(11) NOT NULL default '0', PRIMARY KEY (CaptureId), KEY Hits (Hits), KEY LastHit (LastHit), KEY TimeMin (TimeMin), KEY TimeAvg (TimeAvg), KEY TimeMax (TimeMax), KEY QueryCrc (QueryCrc)); DELETE FROM Cache WHERE VarName = 'sections_parsed'; DELETE FROM Cache WHERE VarName LIKE 'mod_rw_%'; Index: branches/RC/core/kernel/utility/cache.php =================================================================== diff -u -N -r10494 -r10516 --- branches/RC/core/kernel/utility/cache.php (.../cache.php) (revision 10494) +++ branches/RC/core/kernel/utility/cache.php (.../cache.php) (revision 10516) @@ -17,7 +17,17 @@ $this->debugCache = $this->Application->isDebugMode() && constOn('DBG_CACHE'); - $this->_storage = new CacheStorage(); + $memcached_servers = 'localhost:11211'; // $this->Application->ConfigValue('MemcachedServers'); + + if ($memcached_servers && class_exists('Memcache')) { + $this->_storage = new MemcacheCacheStorage($memcached_servers); + } + else if (false || $this->Application->ConfigValue('UseFileCache')) { + $this->_storage = new FileCacheStorage('file_cache.tmp'); + } + else { + $this->_storage = new CacheStorage(); + } } /** @@ -27,9 +37,9 @@ * @param int $key key name to add to cache * @param mixed $value value of chached record */ - function setCache($cache_name, $key, $value) + function setCache($cache_name, $key, $value, $expires = 3600) { - $this->_storage->set($cache_name, $key, $value); + $this->_storage->set($cache_name, $key, $value, $expires); } /** @@ -91,14 +101,29 @@ class CacheStorage extends Params { - function set($cache_name, $key, $value) + /** + * Stores value to cache + * + * @param string $cache_name + * @param string $key + * @param mixed $value + * @param int $expires cache record expiration time in seconds + */ + function set($cache_name, $key, $value, $expires) { $cache = parent::Get($cache_name, Array()); $cache[$key] = $value; parent::Set($cache_name, $cache); } + /** + * Returns value from cache + * + * @param string $cache_name + * @param string $key + * @return mixed + */ function get($cache_name, $key) { $cache = parent::Get($cache_name, Array()); @@ -107,5 +132,111 @@ return $ret; } } - + + class MemcacheCacheStorage { + + /** + * Memcache connection + * + * @var Memcache + */ + var $_handler = null; + + function MemcacheCacheStorage($servers) + { + $this->_handler = new Memcache; + + $servers = explode(';', $servers); + foreach ($servers as $server) { + list ($server, $port) = strpos($server, ':') !== false ? explode(':', $server, 2) : Array ($server, 11211); + $this->_handler->addServer($server, $port); + } + } + + /** + * Stores value to cache + * + * @param string $cache_name + * @param string $key + * @param mixed $value + * @param int $expires cache record expiration time in seconds + */ + function set($cache_name, $key, $value, $expires) + { + $this->_handler->set($cache_name . '-' . $key, $value, false, $expires); // false could be MEMCACHE_COMPRESSED to compress values in memory + } + + /** + * Returns value from cache + * + * @param string $cache_name + * @param string $key + * @return mixed + */ + function get($cache_name, $key) + { + return $this->_handler->get($cache_name . '-' . $key); + } + } + + class FileCacheStorage extends Params { + + /** + * Expiration time for each variable in cache + * + * @var resource + */ + var $_expiration = Array (); + + /** + * Filename for storing cache + * + * @var string + */ + var $_filename = ''; + + function FileCacheStorage($filename = '') + { + $this->_filename = (defined('WRITEABLE') ? WRITEABLE.'/cache' : FULL_PATH.'/kernel/cache') . '/' . $filename; + + if (file_exists($this->_filename)) { + $cache_data = unserialize(file_get_contents($this->_filename)); + } + else { + $cache_data = Array (); + } + } + + /** + * Stores value to cache + * + * @param string $cache_name + * @param string $key + * @param mixed $value + * @param int $expires cache record expiration time in seconds + */ + function set($cache_name, $key, $value, $expires) + { + $cache = parent::Get($cache_name, Array()); + $cache[$key] = $value; + + parent::Set($cache_name, $cache); + } + + /** + * Returns value from cache + * + * @param string $cache_name + * @param string $key + * @return mixed + */ + function get($cache_name, $key) + { + $cache = parent::Get($cache_name, Array()); + $ret = array_key_exists($key, $cache) ? $cache[$key] : false; + + return $ret; + } + } + ?> \ No newline at end of file Index: branches/RC/core/kernel/application.php =================================================================== diff -u -N -r10494 -r10516 --- branches/RC/core/kernel/application.php (.../application.php) (revision 10494) +++ branches/RC/core/kernel/application.php (.../application.php) (revision 10516) @@ -869,6 +869,7 @@ $this->_updateAverageStatistics($data, 'SqlCount', $query_statistics['count']); $data['Hits']++; + $data['LastHit'] = adodb_mktime(); $this->Conn->doUpdate($data, TABLE_PREFIX . 'StatisticsCapture', 'StatisticsId = ' . $data['StatisticsId']); } @@ -878,6 +879,7 @@ $data['SqlCountMin'] = $data['SqlCountAvg'] = $data['SqlCountMax'] = $query_statistics['count']; $data['TemplateName'] = $this->GetVar('t'); $data['Hits'] = 1; + $data['LastHit'] = adodb_mktime(); $this->Conn->doInsert($data, TABLE_PREFIX . 'StatisticsCapture'); } } @@ -919,6 +921,7 @@ $data['TemplateNames'] = implode(',', array_unique($template_names)); $data['Hits']++; + $data['LastHit'] = adodb_mktime(); $this->Conn->doUpdate($data, TABLE_PREFIX . 'SlowSqlCapture', 'CaptureId = ' . $data['CaptureId']); } @@ -928,6 +931,7 @@ $data['QueryCrc'] = $query_crc; $data['TemplateNames'] = $this->GetVar('t'); $data['Hits'] = 1; + $data['LastHit'] = adodb_mktime(); $this->Conn->doInsert($data, TABLE_PREFIX . 'SlowSqlCapture'); } @@ -2683,6 +2687,28 @@ return $xml_version ? 'GetDBField('Charset').'"?>' : ''; } + + /** + * Returns category tree + * + * @param int $category_id + * @return Array + */ + function getTreeIndex($category_id) + { + $category_template = $this->getFilename('c', $category_id); // to rebuild "category_tree" cache + + $tree_index = $this->getCache('category_tree', $category_id); + + if ($tree_index) { + $ret = Array (); + list ($ret['TreeLeft'], $ret['TreeRight']) = explode(';', $tree_index); + + return $ret; + } + + return false; + } } ?> \ No newline at end of file