Added preload caching
This commit is contained in:
parent
d7822a03e8
commit
35426141e5
@ -25,6 +25,60 @@ class ORMTSM extends ORM {
|
||||
protected $_formated = FALSE;
|
||||
protected $_formats = array();
|
||||
|
||||
public function find() {
|
||||
// Check if we can preload our data and havent already done it
|
||||
if ($time = $this->isCacheable() AND is_null(Cache::instance()->get($cache_key = 'PRELOAD:'.$this->_table_name))) {
|
||||
|
||||
// Firstly set our cache, so that we dont get in a loop
|
||||
Cache::instance()->set($cache_key,TRUE,$time-1);
|
||||
|
||||
// Find all records of this type
|
||||
$c = get_class($this);
|
||||
$x = new $c;
|
||||
|
||||
foreach ($x->find_all() as $record) {
|
||||
// Simulate loading the record so that we can get the SQL to use as our cache key
|
||||
$y = new $c;
|
||||
$y->where($y->_primary_key,'=',(string)$record);
|
||||
|
||||
// Code, as extracted from ORM to complete building the SQL
|
||||
$y->_build(Database::SELECT);
|
||||
$y->_db_builder->from($y->_table_name);
|
||||
if (! isset($y->_db_applied['order_by']) AND ! empty($y->_sorting))
|
||||
foreach ($y->_sorting as $column => $direction) {
|
||||
if (strpos($column, '.') === FALSE)
|
||||
// Sorting column for use in JOINs
|
||||
$column = ($y->_disable_join_table_name ? '' : $y->_table_name.'.').$column;
|
||||
|
||||
$y->_db_builder->order_by($column, $direction);
|
||||
}
|
||||
|
||||
// Set the cache key based on the database instance name and SQL
|
||||
$cache_key = 'Database::query("'.$y->_db.'", "'.(string)$y->_db_builder.'")';
|
||||
unset($y);
|
||||
|
||||
// Cache the record, our subsequent find should get a cache hit now.
|
||||
Kohana::cache($cache_key, array($record->as_array()), $time);
|
||||
}
|
||||
|
||||
unset($x);
|
||||
}
|
||||
|
||||
// Contiue as normal
|
||||
return parent::find();
|
||||
}
|
||||
|
||||
private function isCacheable() {
|
||||
$preload = array('NODES','VOLUMES');
|
||||
|
||||
$config = Kohana::config('database')->{Database::$default};
|
||||
|
||||
if ($config['caching'] AND isset($config['cachepreload'][$this->_table_name]) AND count($this->_db_pending) == 1 AND $this->_db_pending[0]['name'] == 'where' AND $this->_db_pending[0]['args'][0] == $this->_primary_key AND $this->_db_pending[0]['args'][1] == '=')
|
||||
return $config['cachepreload'][$this->_table_name];
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
protected function _load_result($multiple = FALSE) {
|
||||
// We'll cache our query results
|
||||
if ($c = $this->_db->caching($this->_table_name))
|
||||
@ -46,7 +100,7 @@ class ORMTSM extends ORM {
|
||||
// Set the cache key based on the database instance name and SQL
|
||||
$cache_key = 'Database::query(LC:'.$this->_table_name.')';
|
||||
|
||||
if ($result = Cache::instance()->get($cache_key))
|
||||
if (! is_null($result = Cache::instance()->get($cache_key)))
|
||||
// Return a cached result
|
||||
return $result;
|
||||
}
|
||||
|
@ -56,6 +56,13 @@ return array
|
||||
'VOLUMES' => 1200,
|
||||
'VOLUMEUSAGE' => 1200,
|
||||
),
|
||||
'cachepreload' => array(
|
||||
'DEVCLASSES' => 1200,
|
||||
'DOMAINS' => 1200,
|
||||
'NODES' => 1200,
|
||||
'STGPOOLS' => 1200,
|
||||
'VOLUMES' => 1200,
|
||||
),
|
||||
'profiling' => TRUE,
|
||||
),
|
||||
);
|
||||
|
@ -107,7 +107,7 @@
|
||||
<td style="width: 100%; vertical-align: top;">
|
||||
<table class="box-full">
|
||||
<tr>
|
||||
<td class="head" colspan="15">Sequential Volumes needed to restore Data for Nodes in this Domain</td>
|
||||
<td class="head" colspan="14">Sequential Volumes needed to restore Data for Nodes in this Domain</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="spacer"> </td>
|
||||
@ -120,7 +120,6 @@
|
||||
<td class="right">Pct %</td>
|
||||
<td class="right">Rec %</td>
|
||||
<td class="right">Mounted</td>
|
||||
<td class="right">Writes</td>
|
||||
<td class="right">R/W Err</td>
|
||||
<td class="right">FS</td>
|
||||
<td class="right">Nodes</td>
|
||||
@ -128,12 +127,12 @@
|
||||
</tr>
|
||||
<?php foreach (Kohana::config('config.tsmdatatypes') as $btype => $ctype) { ?>
|
||||
<tr class="subhead">
|
||||
<td colspan="15"><?php echo $btype; ?></td>
|
||||
<td colspan="14"><?php echo $btype; ?></td>
|
||||
</tr>
|
||||
<?php foreach (Kohana::config('config.tsmpooltypes') as $type) { ?>
|
||||
<tr class="subhead">
|
||||
<td> </td>
|
||||
<td colspan="14"><?php echo $type; ?></td>
|
||||
<td colspan="13"><?php echo $type; ?></td>
|
||||
</tr>
|
||||
<?php $i=0;foreach ($do->getStoragePoolsType($btype,$type) as $spo) { ?>
|
||||
<tr class="subhead">
|
||||
@ -150,7 +149,6 @@
|
||||
<td class="data-right"><?php echo $vuo->VOLUME->display('PCT_UTILIZED'); ?></td>
|
||||
<td class="data-right"><?php echo $vuo->VOLUME->display('PCT_RECLAIM'); ?></td>
|
||||
<td class="data-right"><?php echo $vuo->VOLUME->display('TIMES_MOUNTED'); ?></td>
|
||||
<td class="data-right"><?php echo $vuo->VOLUME->display('WRITE_PASS'); ?></td>
|
||||
<td class="data-right"><?php printf('%s/%s',$vuo->VOLUME->READ_ERRORS,$vuo->VOLUME->WRITE_ERRORS); ?></td>
|
||||
<td class="data-right"><?php echo $vuo->VOLUME->getFSOnVol($ctype); ?></td>
|
||||
<td class="data-right"><?php echo $vuo->VOLUME->getNodesOnVol($ctype); ?></td>
|
||||
|
Reference in New Issue
Block a user