mirror of
https://github.com/Oreolek/ifhub.club.git
synced 2024-06-26 03:30:48 +03:00
Кеширование SHOW COLUMNS в ORM
This commit is contained in:
parent
9d34c7e374
commit
d4db267663
|
@ -241,15 +241,18 @@ class MapperORM extends Mapper {
|
|||
}
|
||||
|
||||
public function ShowColumnsFromTable($sTableName) {
|
||||
$sql = "SHOW COLUMNS FROM ".$sTableName;
|
||||
$aItems = array();
|
||||
if($aRows=$this->oDb->select($sql)) {
|
||||
foreach($aRows as $aRow) {
|
||||
$aItems[] = $aRow['Field'];
|
||||
if($aRow['Key']=='PRI') {
|
||||
$aItems['#primary_key'] = $aRow['Field'];
|
||||
if (false === ($aItems = Engine::getInstance()->Cache_GetLife("columns_table_{$sTableName}"))) {
|
||||
$sql = "SHOW COLUMNS FROM ".$sTableName;
|
||||
$aItems = array();
|
||||
if($aRows=$this->oDb->select($sql)) {
|
||||
foreach($aRows as $aRow) {
|
||||
$aItems[] = $aRow['Field'];
|
||||
if($aRow['Key']=='PRI') {
|
||||
$aItems['#primary_key'] = $aRow['Field'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Engine::getInstance()->Cache_SetLife($aItems, "columns_table_{$sTableName}");
|
||||
}
|
||||
return $aItems;
|
||||
}
|
||||
|
|
|
@ -181,12 +181,7 @@ abstract class Plugin extends Object {
|
|||
* @return unknown
|
||||
*/
|
||||
protected function isTableExists($sTableName) {
|
||||
$sTableName = str_replace('prefix_', Config::Get('db.table.prefix'), $sTableName);
|
||||
$sQuery="SHOW TABLES LIKE '{$sTableName}'";
|
||||
if ($aRows=$this->Database_GetConnect()->select($sQuery)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return $this->Database_isTableExists($sTableName);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
24
engine/modules/cache/Cache.class.php
vendored
24
engine/modules/cache/Cache.class.php
vendored
|
@ -51,6 +51,7 @@ class ModuleCache extends Module {
|
|||
'count_set' => 0,
|
||||
);
|
||||
|
||||
protected $aStoreLife=array();
|
||||
/**
|
||||
* Инициализируем нужный тип кеша
|
||||
*
|
||||
|
@ -230,5 +231,28 @@ class ModuleCache extends Module {
|
|||
public function GetStats() {
|
||||
return $this->aStats;
|
||||
}
|
||||
|
||||
/**
|
||||
* Сохраняет значение в кеше на время исполнения скрипта (некий аналог Registry)
|
||||
*
|
||||
* @param unknown_type $data
|
||||
* @param unknown_type $sName
|
||||
*/
|
||||
public function SetLife($data,$sName) {
|
||||
$this->aStoreLife[$sName]=$data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Получает значение из текущего кеша скрипта
|
||||
*
|
||||
* @param unknown_type $sName
|
||||
* @return unknown
|
||||
*/
|
||||
public function GetLife($sName) {
|
||||
if (key_exists($sName,$this->aStoreLife)) {
|
||||
return $this->aStoreLife[$sName];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -144,6 +144,16 @@ class ModuleDatabase extends Module {
|
|||
}
|
||||
return array('result'=>false,'errors'=>$aErrors);
|
||||
}
|
||||
|
||||
public function isTableExists($sTableName,$aConfig=null) {
|
||||
$sTableName = str_replace('prefix_', Config::Get('db.table.prefix'), $sTableName);
|
||||
$sQuery="SHOW TABLES LIKE '{$sTableName}'";
|
||||
if ($aRows=$this->GetConnect($aConfig)->select($sQuery)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue