mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-04-23 04:12:18 +09:00
git-svn-id: http://xe-core.googlecode.com/svn/sandbox@7440 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
parent
aff477dd54
commit
e5c5449be4
9 changed files with 38 additions and 179 deletions
|
|
@ -44,9 +44,6 @@
|
|||
var $supported_list = array(); ///< list of supported db, (will be written by classes/DB/DB***.class.php)
|
||||
|
||||
var $cache_file = 'files/cache/queries/'; ///< location of query cache
|
||||
var $path;
|
||||
var $tableMtime = array();
|
||||
var $disabled_cache_tables = array('session','counter_log','counter_site_status','counter_status');
|
||||
|
||||
/**
|
||||
* @brief returns instance of certain db type
|
||||
|
|
@ -62,11 +59,9 @@
|
|||
$class_file = sprintf("%sclasses/db/%s.class.php", _XE_PATH_, $class_name);
|
||||
if(!file_exists($class_file)) new Object(-1, 'msg_db_not_setted');
|
||||
|
||||
require_once($class_file);
|
||||
require_once($class_file);
|
||||
$eval_str = sprintf('$GLOBALS[\'__DB__\'][\''.$db_type.'\'] = new %s();', $class_name);
|
||||
eval($eval_str);
|
||||
|
||||
register_shutdown_function(array(&$GLOBALS['__DB__'][$db_type],'_updateTableMtime'));
|
||||
}
|
||||
|
||||
return $GLOBALS['__DB__'][$db_type];
|
||||
|
|
@ -242,7 +237,7 @@
|
|||
* @return result of query
|
||||
* @remarks this function finds xml file or cache file of $query_id, compiles it and then execute it
|
||||
**/
|
||||
function executeQuery($query_id, $args = NULL, $update_mtime = true) {
|
||||
function executeQuery($query_id, $args = NULL) {
|
||||
if(!$query_id) return new Object(-1, 'msg_invalid_queryid');
|
||||
|
||||
$id_args = explode('.', $query_id);
|
||||
|
|
@ -265,7 +260,7 @@
|
|||
$cache_file = $this->checkQueryCacheFile($query_id, $xml_file);
|
||||
|
||||
// execute query
|
||||
return $this->_executeQuery($cache_file, $args, $query_id, $update_mtime);
|
||||
return $this->_executeQuery($cache_file, $args, $query_id);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -301,7 +296,7 @@
|
|||
* @param[in] $query_id query id
|
||||
* @return result of query
|
||||
**/
|
||||
function _executeQuery($cache_file, $source_args, $query_id, $update_mtime = true) {
|
||||
function _executeQuery($cache_file, $source_args, $query_id) {
|
||||
global $lang;
|
||||
|
||||
if(!file_exists($cache_file)) return new Object(-1, 'msg_invalid_queryid');
|
||||
|
|
@ -316,39 +311,21 @@
|
|||
// execute appropriate query
|
||||
switch($output->action) {
|
||||
case 'insert' :
|
||||
//$this->resetCountCache($output->tables);
|
||||
if($update_mtime) $this->updateTableMtime($output->tables);
|
||||
$this->resetCountCache($output->tables);
|
||||
$output = $this->_executeInsertAct($output);
|
||||
break;
|
||||
case 'update' :
|
||||
//$this->resetCountCache($output->tables);
|
||||
if($update_mtime) $this->updateTableMtime($output->tables);
|
||||
$this->resetCountCache($output->tables);
|
||||
$output = $this->_executeUpdateAct($output);
|
||||
break;
|
||||
case 'delete' :
|
||||
//$this->resetCountCache($output->tables);
|
||||
if($update_mtime) $this->updateTableMtime($output->tables);
|
||||
$this->resetCountCache($output->tables);
|
||||
$output = $this->_executeDeleteAct($output);
|
||||
break;
|
||||
case 'select' :
|
||||
if(count(array_intersect($this->disabled_cache_tables, $output->tables))==0){
|
||||
$CacheHandler = &CacheHandler::getInstance();
|
||||
$cache_support = $CacheHandler->isSupport();
|
||||
|
||||
if($cache_support){
|
||||
$cache_key = $query_id . serialize($source_args);
|
||||
$buff = $CacheHandler->get($cache_key, $this->_getTableMtime($output->tables));
|
||||
if($buff){
|
||||
return $buff;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$output = $this->_executeSelectAct($output);
|
||||
if($cache_support && $cache_key) $CacheHandler->put($cache_key, $output);
|
||||
break;
|
||||
}
|
||||
|
||||
if($this->isError()) $output = $this->getError();
|
||||
else if(!is_a($output, 'Object') && !is_subclass_of($output, 'Object')) $output = new Object();
|
||||
$output->add('_query', $this->query);
|
||||
|
|
@ -357,43 +334,6 @@
|
|||
return $output;
|
||||
}
|
||||
|
||||
function updateTableMtime($tables){
|
||||
$this->tableMtime = array_merge($this->tableMtime,$tables);
|
||||
}
|
||||
|
||||
function _updateTableMtime(){
|
||||
$tables = array_unique($this->tableMtime);
|
||||
foreach($tables as $table){
|
||||
if(!in_array($table, $this->disabled_cache_tables)){
|
||||
touch(_XE_PATH_.'files/cache/'.$table);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function _getTableMtime($tables){
|
||||
$tablemtime = array(null);
|
||||
foreach($tables as $table){
|
||||
if($GLOBALS['TABLEMTIME'][$table]){
|
||||
$tablemtime[] = $GLOBALS['TABLEMTIME'][$table];
|
||||
continue;
|
||||
}
|
||||
|
||||
$file = _XE_PATH_.'files/cache/'.$table;
|
||||
if(file_exists($file)){
|
||||
if(!$GLOBALS['TABLEMTIME'][$table]){
|
||||
$GLOBALS['TABLEMTIME'][$table] = filemtime($file);
|
||||
}
|
||||
|
||||
$tablemtime[] = $GLOBALS['TABLEMTIME'][$table];
|
||||
}else{
|
||||
touch($file);
|
||||
}
|
||||
}
|
||||
|
||||
$mtime = max($tablemtime);
|
||||
return !$mtime ? time() : $mtime;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief check $val with $filter_type
|
||||
* @param[in] $key key value
|
||||
|
|
|
|||
|
|
@ -149,7 +149,7 @@
|
|||
**/
|
||||
function _query($query) {
|
||||
if(!$this->isConnected()) return;
|
||||
//debugPrint($query);
|
||||
|
||||
// 쿼리 시작을 알림
|
||||
$this->actStart($query);
|
||||
|
||||
|
|
@ -599,47 +599,18 @@
|
|||
function _getNavigationData($table_list, $columns, $left_join, $condition, $output) {
|
||||
require_once(_XE_PATH_.'classes/page/PageHandler.class.php');
|
||||
|
||||
$CacheHandler = &CacheHandler::getInstance();
|
||||
$cache_support = $CacheHandler->isSupport();
|
||||
|
||||
if($cache_support){
|
||||
|
||||
// 전체 개수를 구함
|
||||
$count_condition = count($output->groups) ? sprintf('%s group by %s', $condition, implode(', ', $output->groups)) : $condition;
|
||||
|
||||
$cache_key = join(',',$output->tables) . $count_condition;
|
||||
$mtime = $this->_getTableMtime($output->tables);
|
||||
|
||||
$total_count = $CacheHandler->get($cache_key, $mtime);
|
||||
|
||||
if(!$total_count){
|
||||
$count_query = sprintf("select count(*) as count from %s %s %s", implode(', ', $table_list), implode(' ', $left_join), $count_condition);
|
||||
if (count($output->groups))
|
||||
$count_query = sprintf('select count(*) as count from (%s) xet', $count_query);
|
||||
$result = $this->_query($count_query);
|
||||
$count_output = $this->_fetch($result);
|
||||
$total_count = (int)$count_output->count;
|
||||
|
||||
$CacheHandler->put($cache_key, $total_count.'');
|
||||
}
|
||||
|
||||
}else{
|
||||
|
||||
// 전체 개수를 구함
|
||||
$count_condition = count($output->groups) ? sprintf('%s group by %s', $condition, implode(', ', $output->groups)) : $condition;
|
||||
$total_count = $this->getCountCache($output->tables, $count_condition);
|
||||
if($total_count === false) {
|
||||
$count_query = sprintf("select count(*) as count from %s %s %s", implode(', ', $table_list), implode(' ', $left_join), $count_condition);
|
||||
if (count($output->groups))
|
||||
$count_query = sprintf('select count(*) as count from (%s) xet', $count_query);
|
||||
$result = $this->_query($count_query);
|
||||
$count_output = $this->_fetch($result);
|
||||
$total_count = (int)$count_output->count;
|
||||
$this->putCountCache($output->tables, $count_condition, $total_count);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 전체 개수를 구함
|
||||
$count_condition = count($output->groups) ? sprintf('%s group by %s', $condition, implode(', ', $output->groups)) : $condition;
|
||||
$total_count = $this->getCountCache($output->tables, $count_condition);
|
||||
if($total_count === false) {
|
||||
$count_query = sprintf("select count(*) as count from %s %s %s", implode(', ', $table_list), implode(' ', $left_join), $count_condition);
|
||||
if (count($output->groups))
|
||||
$count_query = sprintf('select count(*) as count from (%s) xet', $count_query);
|
||||
$result = $this->_query($count_query);
|
||||
$count_output = $this->_fetch($result);
|
||||
$total_count = (int)$count_output->count;
|
||||
$this->putCountCache($output->tables, $count_condition, $total_count);
|
||||
}
|
||||
|
||||
$list_count = $output->list_count['value'];
|
||||
if(!$list_count) $list_count = 20;
|
||||
|
|
@ -681,9 +652,6 @@
|
|||
}
|
||||
|
||||
$query = sprintf('%s limit %d, %d', $query, $start_count, $list_count);
|
||||
|
||||
|
||||
|
||||
$result = $this->_query($query);
|
||||
if($this->isError()) {
|
||||
$buff = new Object();
|
||||
|
|
|
|||
|
|
@ -55,25 +55,14 @@
|
|||
$this->tpl_path = preg_replace('/^\.\//','',$tpl_path);
|
||||
$this->tpl_file = $tpl_file;
|
||||
|
||||
$CacheHandler = &CacheHandler::getInstance('template');
|
||||
if($CacheHandler->isSupport()){
|
||||
$buff = $CacheHandler->get('template:'.$tpl_file, filemtime(FileHandler::getRealPath($tpl_file)));
|
||||
if(!$buff){
|
||||
$buff = $this->_compileTplFile($tpl_file);
|
||||
$CacheHandler->put('template:'.$tpl_file, $buff);
|
||||
}
|
||||
// get cached compiled file name
|
||||
$compiled_tpl_file = FileHandler::getRealPath($this->_getCompiledFileName($tpl_file));
|
||||
|
||||
$output = $this->_fetch('', $buff, $tpl_path);
|
||||
}else{
|
||||
// get cached compiled file name
|
||||
$compiled_tpl_file = FileHandler::getRealPath($this->_getCompiledFileName($tpl_file));
|
||||
// compile
|
||||
$buff = $this->_compile($tpl_file, $compiled_tpl_file);
|
||||
|
||||
// compile
|
||||
$buff = $this->_compile($tpl_file, $compiled_tpl_file);
|
||||
|
||||
// make a result, combining Context and compiled_tpl_file
|
||||
$output = $this->_fetch($compiled_tpl_file, $buff, $tpl_path);
|
||||
}
|
||||
// make a result, combining Context and compiled_tpl_file
|
||||
$output = $this->_fetch($compiled_tpl_file, $buff, $tpl_path);
|
||||
|
||||
if(__DEBUG__==3 ) $GLOBALS['__template_elapsed__'] += getMicroTime() - $start;
|
||||
|
||||
|
|
@ -331,7 +320,7 @@
|
|||
$output = sprintf(
|
||||
'<?php%s'.
|
||||
'$oTemplate = &TemplateHandler::getInstance();%s'.
|
||||
'echo $oTemplate->compile(\'%s\',\'%s\');%s'.
|
||||
'print $oTemplate->compile(\'%s\',\'%s\');%s'.
|
||||
'?>%s',
|
||||
|
||||
"\n",
|
||||
|
|
@ -530,6 +519,5 @@
|
|||
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue