mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-07 02:31:40 +09:00
1. DB의 테이블명과 alias의 배열 위치를 변경하여 한 쿼리에서 하나의 테이블을 여러번 alias하여 사용할 수 있도록 수정. 2. 네비게이션을 위한 count(*) 구할때 파일로 캐싱기능을 두어서 DB부하를 줄이고 속도 증가 3. DB.class.php파일의 변경시점을 xml query cache file에 적용하여 코어코드 변경시 xml query cache 파일이 재생성 되도록 수정 4. 전체 캐시파일 재생성시 카운터 캐시 파일 디렉토리(./files/cache/db)의 내용도 지우도록 추가
git-svn-id: http://xe-core.googlecode.com/svn/sandbox@3715 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
parent
c3cb138ff7
commit
edf336668c
9 changed files with 143 additions and 47 deletions
|
|
@ -15,6 +15,8 @@
|
|||
|
||||
class DB {
|
||||
|
||||
var $count_cache_path = './files/cache/db';
|
||||
|
||||
var $cond_operation = array( ///< 조건문에서 조건을 등호로 표시하는 변수
|
||||
'equal' => '=',
|
||||
'more' => '>=',
|
||||
|
|
@ -220,9 +222,11 @@
|
|||
|
||||
// 일단 cache 파일을 찾아본다
|
||||
$cache_file = sprintf('%s%s.cache.php', $this->cache_file, $query_id);
|
||||
if(file_exists($cache_file)) $cache_time = filemtime($cache_file);
|
||||
else $cache_time = -1;
|
||||
|
||||
// 없으면 원본 쿼리 xml파일을 찾아서 파싱을 한다
|
||||
if(!file_exists($cache_file)||filemtime($cache_file)<filemtime($xml_file)) {
|
||||
// 캐시 파일이 없거나 시간 비교하여 최근것이 아니면 원본 쿼리 xml파일을 찾아서 파싱을 한다
|
||||
if($cache_time<filemtime($xml_file) || $cache_time < filemtime('./classes/db/DB.class.php')) {
|
||||
require_once('./classes/xml/XmlQueryParser.class.php');
|
||||
$oParser = new XmlQueryParser();
|
||||
$oParser->parse($query_id, $xml_file, $cache_file);
|
||||
|
|
@ -250,12 +254,15 @@
|
|||
// action값에 따라서 쿼리 생성으로 돌입
|
||||
switch($output->action) {
|
||||
case 'insert' :
|
||||
$this->resetCountCache($output->tables);
|
||||
$output = $this->_executeInsertAct($output);
|
||||
break;
|
||||
case 'update' :
|
||||
$this->resetCountCache($output->tables);
|
||||
$output = $this->_executeUpdateAct($output);
|
||||
break;
|
||||
case 'delete' :
|
||||
$this->resetCountCache($output->tables);
|
||||
$output = $this->_executeDeleteAct($output);
|
||||
break;
|
||||
case 'select' :
|
||||
|
|
@ -413,7 +420,69 @@
|
|||
}
|
||||
|
||||
return $conditions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 카운터 캐시 데이터 얻어오기
|
||||
**/
|
||||
function getCountCache($tables, $condition) {
|
||||
if(!$tables) return false;
|
||||
if(!is_dir($this->count_cache_path)) return FileHandler::makeDir($this->count_cache_path);
|
||||
|
||||
$condition = md5($condition);
|
||||
|
||||
if(!is_array($tables)) $tables_str = $tables;
|
||||
else $tables_str = implode('.',$tables);
|
||||
|
||||
$cache_path = sprintf('%s/%s%s', $this->count_cache_path, $this->prefix, $tables_str);
|
||||
if(!is_dir($cache_path)) FileHandler::makeDir($cache_path);
|
||||
|
||||
$cache_filename = sprintf('%s/%s.%s', $cache_path, $tables_str, $condition);
|
||||
if(!file_exists($cache_filename)) return false;
|
||||
|
||||
$cache_mtime = filemtime($cache_filename);
|
||||
|
||||
if(!is_array($tables)) $tables = array($tables);
|
||||
foreach($tables as $alias => $table) {
|
||||
$table_filename = sprintf('%s/cache.%s%s', $this->count_cache_path, $this->prefix, $table) ;
|
||||
if(file_exists($table_filename) && filemtime($table_filename) > $cache_mtime) return false;
|
||||
}
|
||||
|
||||
$count = (int)FileHandler::readFile($cache_filename);
|
||||
return $count;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 카운터 캐시 데이터 저장
|
||||
**/
|
||||
function putCountCache($tables, $condition, $count = 0) {
|
||||
if(!$tables) return false;
|
||||
if(!is_dir($this->count_cache_path)) return FileHandler::makeDir($this->count_cache_path);
|
||||
|
||||
$condition = md5($condition);
|
||||
|
||||
if(!is_array($tables)) $tables_str = $tables;
|
||||
else $tables_str = implode('.',$tables);
|
||||
|
||||
$cache_path = sprintf('%s/%s%s', $this->count_cache_path, $this->prefix, $tables_str);
|
||||
if(!is_dir($cache_path)) FileHandler::makeDir($cache_path);
|
||||
|
||||
$cache_filename = sprintf('%s/%s.%s', $cache_path, $tables_str, $condition);
|
||||
|
||||
FileHandler::writeFile($cache_filename, $count);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 카운터 캐시 리셋
|
||||
**/
|
||||
function resetCountCache($tables) {
|
||||
if(!$tables) return false;
|
||||
if(!is_dir($this->count_cache_path)) return FileHandler::makeDir($this->count_cache_path);
|
||||
|
||||
if(!is_array($tables)) $tables = array($tables);
|
||||
foreach($tables as $alias => $table) FileHandler::writeFile( sprintf('%s/cache.%s%s', $this->count_cache_path, $this->prefix, $table), '' );
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -415,7 +415,7 @@
|
|||
function _executeInsertAct($output) {
|
||||
// 테이블 정리
|
||||
foreach($output->tables as $key => $val) {
|
||||
$table_list[] = '"'.$this->prefix.$key.'"';
|
||||
$table_list[] = '"'.$this->prefix.$val.'"';
|
||||
}
|
||||
|
||||
// 컬럼 정리
|
||||
|
|
@ -456,7 +456,7 @@
|
|||
function _executeUpdateAct($output) {
|
||||
// 테이블 정리
|
||||
foreach($output->tables as $key => $val) {
|
||||
$table_list[] = "\"".$this->prefix.$key."\" as ".$val;
|
||||
$table_list[] = "\"".$this->prefix.$val."\" as ".$key;
|
||||
}
|
||||
|
||||
// 컬럼 정리
|
||||
|
|
@ -503,7 +503,7 @@
|
|||
function _executeDeleteAct($output) {
|
||||
// 테이블 정리
|
||||
foreach($output->tables as $key => $val) {
|
||||
$table_list[] = '"'.$this->prefix.$key.'"';
|
||||
$table_list[] = '"'.$this->prefix.$val.'"';
|
||||
}
|
||||
|
||||
// 조건절 정리
|
||||
|
|
@ -524,7 +524,7 @@
|
|||
// 테이블 정리
|
||||
$table_list = array();
|
||||
foreach($output->tables as $key => $val) {
|
||||
$table_list[] = '"'.$this->prefix.$key.'" as '.$val;
|
||||
$table_list[] = '"'.$this->prefix.$val.'" as '.$key;
|
||||
}
|
||||
|
||||
if(!$output->columns) {
|
||||
|
|
@ -668,9 +668,13 @@
|
|||
|
||||
// 전체 개수를 구함
|
||||
$count_query = sprintf('select count(*) as "count" from %s %s', implode(',',$table_list), $condition);
|
||||
$result = $this->_query($count_query);
|
||||
$count_output = $this->_fetch($result);
|
||||
$total_count = (int)$count_output->count;
|
||||
$total_count = $this->getCountCache($output->tables, $condition);
|
||||
if($total_count === false) {
|
||||
$result = $this->_query($count_query);
|
||||
$count_output = $this->_fetch($result);
|
||||
$total_count = (int)$count_output->count;
|
||||
$this->putCountCache($output->tables, $condition, $total_count);
|
||||
}
|
||||
|
||||
$list_count = $output->list_count['value'];
|
||||
if(!$list_count) $list_count = 20;
|
||||
|
|
|
|||
|
|
@ -396,7 +396,7 @@
|
|||
function _executeInsertAct($output) {
|
||||
// 테이블 정리
|
||||
foreach($output->tables as $key => $val) {
|
||||
$table_list[] = '`'.$this->prefix.$key.'`';
|
||||
$table_list[] = '`'.$this->prefix.$val.'`';
|
||||
}
|
||||
|
||||
// 컬럼 정리
|
||||
|
|
@ -422,7 +422,7 @@
|
|||
function _executeUpdateAct($output) {
|
||||
// 테이블 정리
|
||||
foreach($output->tables as $key => $val) {
|
||||
$table_list[] = '`'.$this->prefix.$key.'` as '.$val;
|
||||
$table_list[] = '`'.$this->prefix.$val.'` as '.$key;
|
||||
}
|
||||
|
||||
// 컬럼 정리
|
||||
|
|
@ -453,7 +453,7 @@
|
|||
function _executeDeleteAct($output) {
|
||||
// 테이블 정리
|
||||
foreach($output->tables as $key => $val) {
|
||||
$table_list[] = '`'.$this->prefix.$key.'`';
|
||||
$table_list[] = '`'.$this->prefix.$val.'`';
|
||||
}
|
||||
|
||||
// 조건절 정리
|
||||
|
|
@ -474,7 +474,7 @@
|
|||
// 테이블 정리
|
||||
$table_list = array();
|
||||
foreach($output->tables as $key => $val) {
|
||||
$table_list[] = '`'.$this->prefix.$key.'` as '.$val;
|
||||
$table_list[] = '`'.$this->prefix.$val.'` as '.$key;
|
||||
}
|
||||
|
||||
if(!$output->columns) {
|
||||
|
|
@ -547,9 +547,13 @@
|
|||
|
||||
// 전체 개수를 구함
|
||||
$count_query = sprintf("select count(*) as count from %s %s", implode(',',$table_list), $condition);
|
||||
$result = $this->_query($count_query);
|
||||
$count_output = $this->_fetch($result);
|
||||
$total_count = (int)$count_output->count;
|
||||
$total_count = $this->getCountCache($output->tables, $condition);
|
||||
if($total_count === false) {
|
||||
$result = $this->_query($count_query);
|
||||
$count_output = $this->_fetch($result);
|
||||
$total_count = (int)$count_output->count;
|
||||
$this->putCountCache($output->tables, $condition, $total_count);
|
||||
}
|
||||
|
||||
$list_count = $output->list_count['value'];
|
||||
if(!$list_count) $list_count = 20;
|
||||
|
|
|
|||
|
|
@ -406,7 +406,7 @@
|
|||
function _executeInsertAct($output) {
|
||||
// 테이블 정리
|
||||
foreach($output->tables as $key => $val) {
|
||||
$table_list[] = '`'.$this->prefix.$key.'`';
|
||||
$table_list[] = '`'.$this->prefix.$val.'`';
|
||||
}
|
||||
|
||||
// 컬럼 정리
|
||||
|
|
@ -432,7 +432,7 @@
|
|||
function _executeUpdateAct($output) {
|
||||
// 테이블 정리
|
||||
foreach($output->tables as $key => $val) {
|
||||
$table_list[] = '`'.$this->prefix.$key.'` as '.$val;
|
||||
$table_list[] = '`'.$this->prefix.$val.'` as '.$key;
|
||||
}
|
||||
|
||||
// 컬럼 정리
|
||||
|
|
@ -463,7 +463,7 @@
|
|||
function _executeDeleteAct($output) {
|
||||
// 테이블 정리
|
||||
foreach($output->tables as $key => $val) {
|
||||
$table_list[] = '`'.$this->prefix.$key.'`';
|
||||
$table_list[] = '`'.$this->prefix.$val.'`';
|
||||
}
|
||||
|
||||
// 조건절 정리
|
||||
|
|
@ -484,7 +484,7 @@
|
|||
// 테이블 정리
|
||||
$table_list = array();
|
||||
foreach($output->tables as $key => $val) {
|
||||
$table_list[] = '`'.$this->prefix.$key.'` as '.$val;
|
||||
$table_list[] = '`'.$this->prefix.$val.'` as '.$key;
|
||||
}
|
||||
|
||||
if(!$output->columns) {
|
||||
|
|
@ -557,9 +557,13 @@
|
|||
|
||||
// 전체 개수를 구함
|
||||
$count_query = sprintf("select count(*) as count from %s %s", implode(',',$table_list), $condition);
|
||||
$result = $this->_query($count_query);
|
||||
$count_output = $this->_fetch($result);
|
||||
$total_count = (int)$count_output->count;
|
||||
$total_count = $this->getCountCache($output->tables, $condition);
|
||||
if($total_count === false) {
|
||||
$result = $this->_query($count_query);
|
||||
$count_output = $this->_fetch($result);
|
||||
$total_count = (int)$count_output->count;
|
||||
$this->putCountCache($output->tables, $condition, $total_count);
|
||||
}
|
||||
|
||||
$list_count = $output->list_count['value'];
|
||||
if(!$list_count) $list_count = 20;
|
||||
|
|
|
|||
|
|
@ -400,7 +400,7 @@
|
|||
function _executeInsertAct($output) {
|
||||
// 테이블 정리
|
||||
foreach($output->tables as $key => $val) {
|
||||
$table_list[] = $this->prefix.$key;
|
||||
$table_list[] = $this->prefix.$val;
|
||||
}
|
||||
|
||||
// 컬럼 정리
|
||||
|
|
@ -426,7 +426,7 @@
|
|||
function _executeUpdateAct($output) {
|
||||
// 테이블 정리
|
||||
foreach($output->tables as $key => $val) {
|
||||
$table_list[] = $this->prefix.$key.' as '.$val;
|
||||
$table_list[] = $this->prefix.$val.' as '.$key;
|
||||
}
|
||||
|
||||
// 컬럼 정리
|
||||
|
|
@ -457,7 +457,7 @@
|
|||
function _executeDeleteAct($output) {
|
||||
// 테이블 정리
|
||||
foreach($output->tables as $key => $val) {
|
||||
$table_list[] = $this->prefix.$key;
|
||||
$table_list[] = $this->prefix.$val;
|
||||
}
|
||||
|
||||
// 조건절 정리
|
||||
|
|
@ -478,7 +478,7 @@
|
|||
// 테이블 정리
|
||||
$table_list = array();
|
||||
foreach($output->tables as $key => $val) {
|
||||
$table_list[] = $this->prefix.$key .' as '.$val;
|
||||
$table_list[] = $this->prefix.$val.' as '.$key;
|
||||
}
|
||||
|
||||
if(!$output->columns) {
|
||||
|
|
@ -548,9 +548,13 @@
|
|||
|
||||
// 전체 개수를 구함
|
||||
$count_query = sprintf("select count(*) as count from %s %s", implode(',',$table_list), $condition);
|
||||
$result = $this->_query($count_query);
|
||||
$count_output = $this->_fetch($result);
|
||||
$total_count = (int)$count_output->count;
|
||||
$total_count = $this->getCountCache($output->tables, $condition);
|
||||
if($total_count === false) {
|
||||
$result = $this->_query($count_query);
|
||||
$count_output = $this->_fetch($result);
|
||||
$total_count = (int)$count_output->count;
|
||||
$this->putCountCache($output->tables, $condition, $total_count);
|
||||
}
|
||||
|
||||
$list_count = $output->list_count['value'];
|
||||
if(!$list_count) $list_count = 20;
|
||||
|
|
|
|||
|
|
@ -382,7 +382,7 @@
|
|||
function _executeInsertAct($output) {
|
||||
// 테이블 정리
|
||||
foreach($output->tables as $key => $val) {
|
||||
$table_list[] = $this->prefix.$key;
|
||||
$table_list[] = $this->prefix.$val;
|
||||
}
|
||||
|
||||
// 컬럼 정리
|
||||
|
|
@ -411,7 +411,7 @@
|
|||
// 대상 테이블이 1개일 경우
|
||||
if($table_count == 1) {
|
||||
// 테이블 정리
|
||||
list($target_table) = array_keys($output->tables);
|
||||
list($target_table) = array_values($output->tables);
|
||||
$target_table = $this->prefix.$target_table;
|
||||
|
||||
// 컬럼 정리
|
||||
|
|
@ -437,7 +437,7 @@
|
|||
} elseif($table_count == 2) {
|
||||
// 테이블 정리
|
||||
foreach($output->tables as $key => $val) {
|
||||
$table_list[$val] = $this->prefix.$val;
|
||||
$table_list[$val] = $this->prefix.$key;
|
||||
}
|
||||
list($source_table, $target_table) = array_values($table_list);
|
||||
|
||||
|
|
@ -474,7 +474,7 @@
|
|||
function _executeDeleteAct($output) {
|
||||
// 테이블 정리
|
||||
foreach($output->tables as $key => $val) {
|
||||
$table_list[] = $this->prefix.$key;
|
||||
$table_list[] = $this->prefix.$val;
|
||||
}
|
||||
|
||||
// 조건절 정리
|
||||
|
|
@ -495,7 +495,7 @@
|
|||
// 테이블 정리
|
||||
$table_list = array();
|
||||
foreach($output->tables as $key => $val) {
|
||||
$table_list[] = $this->prefix.$key.' as '.$val;
|
||||
$table_list[] = $this->prefix.$val.' as '.$key;
|
||||
}
|
||||
|
||||
if(!$output->columns) {
|
||||
|
|
@ -568,9 +568,13 @@
|
|||
|
||||
// 전체 개수를 구함
|
||||
$count_query = sprintf("select count(*) as count from %s %s", implode(',',$table_list), $condition);
|
||||
$result = $this->_query($count_query);
|
||||
$count_output = $this->_fetch($result);
|
||||
$total_count = (int)$count_output->count;
|
||||
$total_count = $this->getCountCache($output->tables, $condition);
|
||||
if($total_count === false) {
|
||||
$result = $this->_query($count_query);
|
||||
$count_output = $this->_fetch($result);
|
||||
$total_count = (int)$count_output->count;
|
||||
$this->putCountCache($output->tables, $condition, $total_count);
|
||||
}
|
||||
|
||||
$list_count = $output->list_count['value'];
|
||||
if(!$list_count) $list_count = 20;
|
||||
|
|
|
|||
|
|
@ -412,7 +412,7 @@
|
|||
function _executeInsertAct($output) {
|
||||
// 테이블 정리
|
||||
foreach($output->tables as $key => $val) {
|
||||
$table_list[] = $this->prefix.$key;
|
||||
$table_list[] = $this->prefix.$val;
|
||||
}
|
||||
|
||||
// 컬럼 정리
|
||||
|
|
@ -450,7 +450,7 @@
|
|||
// 대상 테이블이 1개일 경우
|
||||
if($table_count == 1) {
|
||||
// 테이블 정리
|
||||
list($target_table) = array_keys($output->tables);
|
||||
list($target_table) = array_values($output->tables);
|
||||
$target_table = $this->prefix.$target_table;
|
||||
|
||||
// 컬럼 정리
|
||||
|
|
@ -476,7 +476,7 @@
|
|||
} elseif($table_count == 2) {
|
||||
// 테이블 정리
|
||||
foreach($output->tables as $key => $val) {
|
||||
$table_list[$val] = $this->prefix.$val;
|
||||
$table_list[$val] = $this->prefix.$key;
|
||||
}
|
||||
list($source_table, $target_table) = array_values($table_list);
|
||||
|
||||
|
|
@ -514,7 +514,7 @@
|
|||
function _executeDeleteAct($output) {
|
||||
// 테이블 정리
|
||||
foreach($output->tables as $key => $val) {
|
||||
$table_list[] = $this->prefix.$key;
|
||||
$table_list[] = $this->prefix.$val;
|
||||
}
|
||||
|
||||
// 조건절 정리
|
||||
|
|
@ -536,7 +536,7 @@
|
|||
// 테이블 정리
|
||||
$table_list = array();
|
||||
foreach($output->tables as $key => $val) {
|
||||
$table_list[] = $this->prefix.$key.' as '.$val;
|
||||
$table_list[] = $this->prefix.$val.' as '.$key;
|
||||
}
|
||||
|
||||
if(!$output->columns) {
|
||||
|
|
@ -609,9 +609,13 @@
|
|||
|
||||
// 전체 개수를 구함
|
||||
$count_query = sprintf("select count(*) as count from %s %s", implode(',',$table_list), $condition);
|
||||
$this->_prepare($count_query);
|
||||
$count_output = $this->_execute();
|
||||
$total_count = (int)$count_output->count;
|
||||
$total_count = $this->getCountCache($output->tables, $condition);
|
||||
if($total_count === false) {
|
||||
$this->_prepare($count_query);
|
||||
$count_output = $this->_execute();
|
||||
$total_count = (int)$count_output->count;
|
||||
$this->putCountCache($output->tables, $condition, $total_count);
|
||||
}
|
||||
|
||||
$list_count = $output->list_count['value'];
|
||||
if(!$list_count) $list_count = 20;
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@
|
|||
$alias = $val->attrs->alias;
|
||||
if(!$alias) $alias = $table_name;
|
||||
|
||||
$output->tables[$table_name] = $alias;
|
||||
$output->tables[$alias] = $table_name;
|
||||
|
||||
// 테이블을 찾아서 컬럼의 속성을 구함
|
||||
$table_file = sprintf('./%s/%s/schemas/%s.xml', 'modules', $module, $table_name);
|
||||
|
|
|
|||
|
|
@ -48,6 +48,9 @@
|
|||
|
||||
// 트리거 정보가 있는 파일 모두 삭제
|
||||
FileHandler::removeFilesInDir("./files/cache/triggers");
|
||||
|
||||
// DB캐시 파일을 모두 삭제
|
||||
FileHandler::removeFilesInDir("./files/cache/db");
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue