close #48 add multi DB object instance caching support

This commit is contained in:
Exodus4D
2015-10-11 19:10:29 +02:00
parent 4770fc771d
commit f0ea85bcd0
8 changed files with 87 additions and 58 deletions

View File

@@ -71,16 +71,18 @@ class Route extends \Controller\AccessController {
$this->f3->exists($cacheKeyIdArray)
){
// get cached values
$this->nameArray = $this->f3->get($cacheKeyNamedArray);
$this->jumpArray = $this->f3->get($cacheKeyJumpArray);
$this->idArray = $this->f3->get($cacheKeyIdArray);
}else{
// nothing cached
$pfDB = $this->getDB('PF');
$query = "SELECT * FROM system_neighbour";
$rows = $this->f3->get('DB')->exec($query, null, $this->jumpDataCacheTime);
$rows = $pfDB->exec($query, null, $this->jumpDataCacheTime);
foreach($rows as $row){
$regionId = $row['regionId'];
@@ -202,8 +204,8 @@ class Route extends \Controller\AccessController {
*/
private function setupSystemJumpTable(){
// switch DB
$this->setDB('CCP');
$pfDB = $this->getDB('PF');
$ccpDB = $this->getDB('CCP');
$query = "SELECT
map_sys.solarSystemID system_id,
@@ -228,18 +230,17 @@ class Route extends \Controller\AccessController {
system_neighbours IS NOT NULL
";
$rows = $this->f3->get('DB')->exec($query);
$rows = $ccpDB->exec($query);
if(count($rows) > 0){
// switch DB back to pathfinder DB
$this->setDB('PF');
// clear cache table
$query = "TRUNCATE system_neighbour";
$this->f3->get('DB')->exec($query);
$pfDB->exec($query);
foreach($rows as $row){
$this->f3->get('DB')->exec("
$pfDB->exec("
INSERT INTO
system_neighbour(
regionId,

View File

@@ -99,24 +99,20 @@ class System extends \Controller\AccessController {
$systemModels = [];
// switch DB
$this->setDB('CCP');
$ccpDB = $this->getDB('CCP');
$this->whereQuery = "WHERE
map_sys." . $column . " IN (" . implode(',', $columnIDs) . ")";
$query = $this->_getQuery();
$rows = $this->f3->get('DB')->exec($query, null, 60 * 60 * 24);
$rows = $ccpDB->exec($query, null, 60 * 60 * 24);
// format result
$mapper = new Mapper\CcpSystemsMapper($rows);
$ccpSystemsData = $mapper->getData();
// switch DB
$this->setDB('PF');
foreach($ccpSystemsData as $ccpSystemData){
$system = Model\BasicModel::getNew('SystemModel');
$system->setData($ccpSystemData);
@@ -132,12 +128,11 @@ class System extends \Controller\AccessController {
*/
public function getSystems(){
// switch DB
$this->setDB('CCP');
$ccpDB = $this->getDB('CCP');
$query = $this->_getQuery();
$rows = $this->f3->get('DB')->exec($query, null, 60 * 60 * 24);
$rows = $ccpDB->exec($query, null, 60 * 60 * 24);
// format result
$mapper = new Mapper\CcpSystemsMapper($rows);
@@ -152,9 +147,7 @@ class System extends \Controller\AccessController {
*/
public function search($f3, $params){
// switch DB
\DB\Database::instance();
$this->setDB('CCP');
$ccpDB = $this->getDB('CCP');
$searchToken = '';
// check for search parameter
@@ -167,7 +160,7 @@ class System extends \Controller\AccessController {
$query = $this->_getQuery();
$rows = $f3->get('DB')->exec($query);
$rows = $ccpDB->exec($query);
// format result
$mapper = new Mapper\CcpSystemsMapper($rows);

View File

@@ -65,9 +65,10 @@ class Controller {
/**
* set change the DB connection
* @param string $database
* @return mixed|void
*/
protected function setDB($database = 'PF'){
DB\Database::instance()->setDB($database);
protected function getDB($database = 'PF'){
return DB\Database::instance()->getDB($database);
}
/**