r7434 fix

git-svn-id: http://xe-core.googlecode.com/svn/sandbox@7438 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
ngleader 2010-05-11 10:20:27 +00:00
parent 96c71e8c9e
commit fe09e55c51
12 changed files with 187 additions and 44 deletions

View file

@ -153,7 +153,7 @@
else $this->allow_rewrite = false;
// add common JS/CSS files
$this->addJsFile("./common/js/jquery.js");
$this->addJsFile("./common/js/jquery.js",true,'',-1000000);
$this->addJsFile("./common/js/x.js");
$this->addJsFile("./common/js/common.js");
$this->addJsFile("./common/js/js_app.js");
@ -1355,8 +1355,8 @@
$filename = trim($list[$i]);
if(!$filename) continue;
if(substr($filename,0,2)=='./') $filename = substr($filename,2);
if(preg_match('/\.js$/i',$filename)) $this->_addJsFile($plugin_path.$filename, false, '', null);
elseif(preg_match('/\.css$/i',$filename)) $this->_addCSSFile($plugin_path.$filename, false, 'all','', null);
if(preg_match('/\.js$/i',$filename)) $this->_addJsFile($plugin_path.$filename, true, '', null);
elseif(preg_match('/\.css$/i',$filename)) $this->_addCSSFile($plugin_path.$filename, true, 'all','', null);
}
if(is_dir($plugin_path.'lang')) $this->_loadLang($plugin_path.'lang');

View file

@ -44,6 +44,9 @@
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
@ -59,9 +62,11 @@
$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];
@ -237,7 +242,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) {
function executeQuery($query_id, $args = NULL, $update_mtime = true) {
if(!$query_id) return new Object(-1, 'msg_invalid_queryid');
$id_args = explode('.', $query_id);
@ -260,7 +265,7 @@
$cache_file = $this->checkQueryCacheFile($query_id, $xml_file);
// execute query
return $this->_executeQuery($cache_file, $args, $query_id);
return $this->_executeQuery($cache_file, $args, $query_id, $update_mtime);
}
@ -296,7 +301,7 @@
* @param[in] $query_id query id
* @return result of query
**/
function _executeQuery($cache_file, $source_args, $query_id) {
function _executeQuery($cache_file, $source_args, $query_id, $update_mtime = true) {
global $lang;
if(!file_exists($cache_file)) return new Object(-1, 'msg_invalid_queryid');
@ -311,21 +316,39 @@
// execute appropriate query
switch($output->action) {
case 'insert' :
$this->resetCountCache($output->tables);
//$this->resetCountCache($output->tables);
if($update_mtime) $this->updateTableMtime($output->tables);
$output = $this->_executeInsertAct($output);
break;
case 'update' :
$this->resetCountCache($output->tables);
//$this->resetCountCache($output->tables);
if($update_mtime) $this->updateTableMtime($output->tables);
$output = $this->_executeUpdateAct($output);
break;
case 'delete' :
$this->resetCountCache($output->tables);
//$this->resetCountCache($output->tables);
if($update_mtime) $this->updateTableMtime($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);
@ -334,6 +357,43 @@
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

View file

@ -149,7 +149,7 @@
**/
function _query($query) {
if(!$this->isConnected()) return;
//debugPrint($query);
// 쿼리 시작을 알림
$this->actStart($query);
@ -599,18 +599,47 @@
function _getNavigationData($table_list, $columns, $left_join, $condition, $output) {
require_once(_XE_PATH_.'classes/page/PageHandler.class.php');
// 전체 개수를 구함
$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);
}
$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);
}
}
$list_count = $output->list_count['value'];
if(!$list_count) $list_count = 20;
@ -652,6 +681,9 @@
}
$query = sprintf('%s limit %d, %d', $query, $start_count, $list_count);
$result = $this->_query($query);
if($this->isError()) {
$buff = new Object();

View file

@ -46,18 +46,19 @@
if(!count($source_files)) return;
$files = array();
$hash = '';
foreach($source_files as $key => $file) {
if(!$file || !$file['file'] || !file_exists($file['file'])) continue;
$file['file'] = $source_files[$key]['file'] = str_replace("\\","/",$file['file']);
if(empty($file['optimized']) || preg_match('/^https?:\/\//i', $file['file']) ) $files[] = $file;
else{
$targets[] = $file;
$hash .= $file['file'];
}
}
if(!count($targets)) return $this->_getOptimizedRemoved($files);
$list_file_hash = md5(join(' ', $targets));
$list_file_hash = md5($hash);
$list_file = FileHandler::getRealPath($this->cache_path . $list_file_hash);
if(!file_exists($list_file)){

View file

@ -55,14 +55,25 @@
$this->tpl_path = preg_replace('/^\.\//','',$tpl_path);
$this->tpl_file = $tpl_file;
// get cached compiled file name
$compiled_tpl_file = FileHandler::getRealPath($this->_getCompiledFileName($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);
}
// compile
$buff = $this->_compile($tpl_file, $compiled_tpl_file);
$output = $this->_fetch('', $buff, $tpl_path);
}else{
// get cached compiled file name
$compiled_tpl_file = FileHandler::getRealPath($this->_getCompiledFileName($tpl_file));
// make a result, combining Context and compiled_tpl_file
$output = $this->_fetch($compiled_tpl_file, $buff, $tpl_path);
// 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);
}
if(__DEBUG__==3 ) $GLOBALS['__template_elapsed__'] += getMicroTime() - $start;
@ -320,7 +331,7 @@
$output = sprintf(
'<?php%s'.
'$oTemplate = &TemplateHandler::getInstance();%s'.
'print $oTemplate->compile(\'%s\',\'%s\');%s'.
'echo $oTemplate->compile(\'%s\',\'%s\');%s'.
'?>%s',
"\n",
@ -519,5 +530,6 @@
return ob_get_clean();
}
}
?>

View file

@ -51,6 +51,7 @@ if($type == '.css'){
header("Content-Type: ".$content_type."; charset=UTF-8");
/*
// return 304
if (!empty($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
$modifiedSince = strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']);
@ -60,7 +61,7 @@ if (!empty($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
exit;
}
}
*/
header("Cache-Control: private, max-age=2592000");
header("Pragma: cache");
header("Connection: close");

View file

@ -61,8 +61,8 @@
* 0 : 제한 없음 (권장하지 않음)
* 1 : 지정한 IP 주소에만 허용
**/
if(!defined('__DEBUG_PROTECT__')) define('__DEBUG_PROTECT__', 1);
if(!defined('__DEBUG_PROTECT_IP__')) define('__DEBUG_PROTECT_IP__', '127.0.0.1');
if(!defined('__DEBUG_PROTECT__')) define('__DEBUG_PROTECT__', 0);
//if(!defined('__DEBUG_PROTECT_IP__')) define('__DEBUG_PROTECT_IP__', '127.0.0.1');
/**
* @brief DB 오류 메세지 출력 정의
@ -85,7 +85,7 @@
* 1 : 사용함
* 대부분의 서버에서는 문제가 없는데 특정 서버군에서 압축전송시 IE에서 오동작을 일으키는경우가 있음
**/
if(!defined('__OB_GZHANDLER_ENABLE__')) define('__OB_GZHANDLER_ENABLE__', 1);
if(!defined('__OB_GZHANDLER_ENABLE__')) define('__OB_GZHANDLER_ENABLE__', 0);
/**
* @brief php unit test (경로/tests/index.php) 실행 유무 지정
@ -134,6 +134,7 @@
require(_XE_PATH_.'classes/xml/XmlParser.class.php');
require(_XE_PATH_.'classes/xml/XmlJsFilter.class.php');
require(_XE_PATH_.'classes/context/Context.class.php');
require(_XE_PATH_.'classes/cache/CacheHandler.class.php');
require(_XE_PATH_.'classes/db/DB.class.php');
require(_XE_PATH_.'classes/file/FileHandler.class.php');
require(_XE_PATH_.'classes/widget/WidgetHandler.class.php');

View file

@ -171,9 +171,9 @@
* @param args object 변수로 선언된 인자값
* @return 처리결과
**/
function executeQuery($query_id, $args = null) {
function executeQuery($query_id, $args = null, $update_mtime = true) {
$oDB = &DB::getInstance();
return $oDB->executeQuery($query_id, $args);
return $oDB->executeQuery($query_id, $args, $update_mtime = true);
}
/**

View file

@ -53,8 +53,10 @@
if($oContext->checkSSO()) {
$oModuleHandler = new ModuleHandler();
if($oModuleHandler->init()) {
$start_time = microtime(1);
$oModule = &$oModuleHandler->procModule();
$oModuleHandler->displayContent($oModule);
debugPrint(microtime(1) - $start_time);
}
}
$oContext->close();

View file

@ -409,6 +409,7 @@
* @brief 문서 삭제
**/
function deleteDocument($document_srl, $is_admin = false) {
// trigger 호출 (before)
$trigger_obj->document_srl = $document_srl;
$output = ModuleHandler::triggerCall('document.deleteDocument', 'before', $trigger_obj);
@ -465,6 +466,7 @@
// commit
$oDB->commit();
return $output;
}
@ -472,6 +474,7 @@
* @brief 문서를 휴지통으로 옮김
**/
function moveDocumentToTrash($obj) {
// 주어진 trash_srl이 없으면 trash_srl 등록
if(!$obj->trash_srl) $trash_args->trash_srl = getNextSequence();
else $trash_args->trash_srl = $obj->trash_srl;
@ -565,7 +568,13 @@
// 조회수 업데이트
$args->document_srl = $document_srl;
$output = executeQuery('document.updateReadedCount', $args);
$output = executeQuery('document.updateReadedCount', $args, false);
$CacheHandler = &CacheHandler::getInstance();
if($CacheHandler->isSupport()){
$readed_count = $oDocument->get('readed_count')+1;
$oDocument->add('readed_count', $readed_count);
$CacheHandler->put('readed_count:'.$document_srl, $readed_count);
}
// 세션 등록
$_SESSION['readed_document'][$document_srl] = true;

View file

@ -56,6 +56,12 @@
$this->add('title', $GLOBALS['XE_DOCUMENT_LIST'][$this->document_srl]->get('title'));
$this->add('content', $GLOBALS['XE_DOCUMENT_LIST'][$this->document_srl]->get('content'));
}
$CacheHandler = &CacheHandler::getInstance();
if($CacheHandler->isSupport()){
$readed_count = $CacheHandler->get('readed_count:'.$document_srl);
if($readed_count) $this->add('readed_count', $readed_count);
}
}
function isExists() {

View file

@ -95,11 +95,12 @@
function getDocument($document_srl=0, $is_admin = false, $load_extra_vars=true) {
if(!$document_srl) return new documentItem();
if(!isset($GLOBALS['XE_DOCUMENT_LIST'][$document_srl])) {
$oDocument = new documentItem($document_srl, true);
$GLOBALS['XE_DOCUMENT_LIST'][$document_srl] = $oDocument;
if($load_extra_vars) $this->setToAllDocumentExtraVars();
}
if(!isset($GLOBALS['XE_DOCUMENT_LIST'][$document_srl])) {
$oDocument = new documentItem($document_srl, true);
$GLOBALS['XE_DOCUMENT_LIST'][$document_srl] = $oDocument;
if($load_extra_vars) $this->setToAllDocumentExtraVars();
}
if($is_admin) $GLOBALS['XE_DOCUMENT_LIST'][$document_srl]->setGrant();
return $GLOBALS['XE_DOCUMENT_LIST'][$document_srl];
@ -160,6 +161,21 @@
if(!in_array($obj->sort_index, array('list_order','regdate','last_update','update_order','readed_count','voted_count','comment_count','trackback_count','uploaded_count','title','category_srl'))) $obj->sort_index = 'list_order';
if(!in_array($obj->order_type, array('desc','asc'))) $obj->order_type = 'asc';
$CacheHandler = &CacheHandler::getInstance();
$cache_support = $CacheHandler->isSupport();
if($cache_support){
$obj->e = $except_notice;
$obj->l = $load_extra_vars;
$oDB = &DB::getInstance();
$mtime = $oDB->_getTableMtime(array('documents'));
$cache_key = 'documentlist'.serialize($obj);
$buff = $CacheHandler->get($cache_key, $mtime);
if($buff){
return $buff;
}
}
// module_srl 대신 mid가 넘어왔을 경우는 직접 module_srl을 구해줌
if($obj->mid) {
$oModuleModel = &getModel('module');
@ -404,6 +420,9 @@
}
}
if($cache_support && $cache_key){
$CacheHandler->put($cache_key, $output);
}
return $output;
}