- added new setup DB indexing for "system_neighbour" table to /setup route, #125

- fixed system "TrueSec" rounding in "routes module", closed #109
This commit is contained in:
Exodus4D
2016-07-15 20:19:48 +02:00
parent 436f40963d
commit 1a12a9fc9b
6 changed files with 193 additions and 88 deletions

View File

@@ -336,79 +336,6 @@ class Route extends \Controller\AccessController {
return $P;
}
/**
* This function is just for setting up the cache table 'system_neighbour' which is used
* for system jump calculation. Call this function manually if CCP adds Systems/Stargates
*/
/*
private function setupSystemJumpTable(){
$pfDB = $this->getDB('PF');
$ccpDB = $this->getDB('CCP');
$query = "SELECT
map_sys.solarSystemID system_id,
map_sys.regionID region_id,
map_sys.constellationID constellation_id,
map_sys.solarSystemName system_name,
ROUND( map_sys.security, 2) system_security,
(
SELECT
GROUP_CONCAT( NULLIF(map_sys_inner.solarSystemName, NULL) SEPARATOR ':')
FROM
mapSolarSystemJumps map_jump INNER JOIN
mapSolarSystems map_sys_inner ON
map_sys_inner.solarSystemID = map_jump.toSolarSystemID
WHERE
map_jump.fromSolarSystemID = map_sys.solarSystemID
) system_neighbours
FROM
mapSolarSystems map_sys
HAVING
-- skip systems without neighbors (e.g. WHs)
system_neighbours IS NOT NULL
";
$rows = $ccpDB->exec($query);
if(count($rows) > 0){
// switch DB back to pathfinder DB
// clear cache table
$query = "TRUNCATE system_neighbour";
$pfDB->exec($query);
foreach($rows as $row){
$pfDB->exec("
INSERT INTO
system_neighbour(
regionId,
constellationId,
systemName,
systemId,
jumpNodes,
trueSec
)
VALUES(
:regionId,
:constellationId,
:systemName,
:systemId,
:jumpNodes,
:trueSec
)",
[
':regionId' => $row['region_id'],
':constellationId' => $row['constellation_id'],
':systemName' => $row['system_name'],
':systemId' => $row['system_id'],
':jumpNodes' => $row['system_neighbours'],
':trueSec' => $row['system_security']
]);
}
}
}
*/
/**
* find a route between two systems (system names)
* $searchDepth for recursive route search (5000 would be best but slow)

View File

@@ -157,6 +157,8 @@ class Setup extends Controller {
return;
}elseif( !empty($params['fixCols']) ){
$fixColumns = true;
}elseif( !empty($params['buildRouteIndex']) ){
$this->setupSystemJumpTable();
}elseif( !empty($params['clearCache']) ){
$this->clearCache($f3);
}
@@ -174,6 +176,9 @@ class Setup extends Controller {
// set database connection information
$f3->set('checkDatabase', $this->checkDatabase($f3, $fixColumns));
// set index information
$f3->set('indexInformation', $this->getIndexData($f3));
// set cache size
$f3->set('cacheSize', $this->getCacheData($f3));
}
@@ -758,6 +763,91 @@ class Setup extends Controller {
return $checkTables;
}
/** get indexed (cache) data information
* @return array
*/
protected function getIndexData(){
$indexInfo = [
'route' => [
'count' => DB\Database::instance()->getRowCount('system_neighbour')
]
];
return $indexInfo;
}
/**
* This function is just for setting up the cache table 'system_neighbour' which is used
* for system jump calculation. Call this function manually when CCP adds Systems/Stargates
*/
protected function setupSystemJumpTable(){
$pfDB = $this->getDB('PF');
$ccpDB = $this->getDB('CCP');
$query = "SELECT
map_sys.solarSystemID system_id,
map_sys.regionID region_id,
map_sys.constellationID constellation_id,
map_sys.solarSystemName system_name,
ROUND( map_sys.security, 4) system_security,
(
SELECT
GROUP_CONCAT( NULLIF(map_sys_inner.solarSystemName, NULL) SEPARATOR ':')
FROM
mapSolarSystemJumps map_jump INNER JOIN
mapSolarSystems map_sys_inner ON
map_sys_inner.solarSystemID = map_jump.toSolarSystemID
WHERE
map_jump.fromSolarSystemID = map_sys.solarSystemID
) system_neighbours
FROM
mapSolarSystems map_sys
HAVING
-- skip systems without neighbors (e.g. WHs)
system_neighbours IS NOT NULL
";
$rows = $ccpDB->exec($query);
if(count($rows) > 0){
// switch DB back to pathfinder DB
// clear cache table
$query = "TRUNCATE system_neighbour";
$pfDB->exec($query);
foreach($rows as $row){
$pfDB->exec("
INSERT INTO
system_neighbour(
regionId,
constellationId,
systemName,
systemId,
jumpNodes,
trueSec
)
VALUES(
:regionId,
:constellationId,
:systemName,
:systemId,
:jumpNodes,
:trueSec
)",
[
':regionId' => $row['region_id'],
':constellationId' => $row['constellation_id'],
':systemName' => $row['system_name'],
':systemId' => $row['system_id'],
':jumpNodes' => $row['system_neighbours'],
':trueSec' => $row['system_security']
]);
}
}
}
/**
* get cache folder size as string
* @param \Base $f3

View File

@@ -102,7 +102,6 @@ class Database extends \Prefab {
* @return SQL
*/
protected function connect($dns, $name, $user, $password){
$db = null;
try {
@@ -117,10 +116,57 @@ class Database extends \Prefab {
}catch(\PDOException $e){
// DB connection error
// -> log it
LogController::getLogger('ERROR')->write($e->getMessage());
self::getLogger()->write($e->getMessage());
}
return $db;
}
/**
* get all table names from a DB
* @param string $database
* @return array|bool
*/
public function getTables($database = 'PF'){
$schema = new SQL\Schema( $this->getDB($database) );
return $schema->getTables();
}
/**
* checks whether a table exists on a DB or not
* @param $table
* @param string $database
* @return bool
*/
public function tableExists($table, $database = 'PF'){
$tableNames = $this->getTables($database);
return in_array($table, $tableNames);
}
/**
* get current row (data) count for an existing table
* -> returns 0 if table not exists or empty
* @param $table
* @param string $database
* @return int
*/
public function getRowCount($table, $database = 'PF') {
$count = 0;
if( $this->tableExists($table, $database) ){
$db = $this->getDB($database);
$countRes = $db->exec("SELECT COUNT(*) `num` FROM " . $db->quotekey($table));
if(isset($countRes[0]['num'])){
$count = (int)$countRes[0]['num'];
}
}
return $count;
}
/**
* get logger for DB logging
* @return \Log
*/
static function getLogger(){
return LogController::getLogger('ERROR');
}
}

File diff suppressed because one or more lines are too long

View File

@@ -1,6 +1,9 @@
{* splash page *}
<include href="templates/ui/splash.html"/>
{* counter for DB warnings (all databases) *}
<set dbWarnings="0" />
<section>
<div class="container">
@@ -423,6 +426,7 @@
<false>
<kbd class="txt-color txt-color-danger">failed</kbd>
<set dbConnectionStatus="Connection failed" />
<set dbWarnings="{{ @dbWarnings }} + 1" />
</false>
</check>
</td>
@@ -698,6 +702,7 @@
<check if="{{ @dbInformation.info.statusCheckCount > 0 }}">
<true>
<h3 class="panel-title txt-color txt-color-warning">{{ @dbInformation.info.statusCheckCount }} warning</h3>
<set dbWarnings="{{ @dbWarnings }} + {{ @dbInformation.info.statusCheckCount }}" />
</true>
<false>
<h3 class="panel-title txt-color txt-color-green">{{ @dbConnectionStatus }}</h3>
@@ -747,17 +752,54 @@
</div>
<h4><i class="fa fa-fw fa-wrench"></i> Administration</h4>
<h4 id="pf-setup-administration"><i class="fa fa-fw fa-wrench"></i> Administration</h4>
<div class="row text-center">
<div class="col-xs-12 col-md-6 pf-landing-pricing-panel">
{* Index *}
<div class="panel panel-default pricing-big">
<div class="panel-heading text-left">
<h3 class="panel-title">
Index data
<i class="fa fa-fw fa-question-circle" title="
Indexed database data is required for some queries (e.g. route finder module).
Building the Index may take a while (~20s). Increase 'max_execution_time' if you run into PHP timeouts."></i>
</h3>
</div>
<div class="panel-body no-padding">
<div class="btn-group btn-group-justified">
<span class="btn btn-default disabled btn-fake">
Route index
<span class="pull-right">
<check if="{{ @indexInformation.route.count }}">
<true>
<kbd class="txt-color txt-color-success">{{ @indexInformation.route.count }} rows</kbd>
</true>
<false>
<kbd class="txt-color txt-color-danger">0 rows</kbd>
</false>
</check>
</span>
</span>
<a href="?buildRouteIndex=1#pf-setup-administration" class="btn btn-primary {{ @dbWarnings ?'disabled':'' }}" role="button">
<i class="fa fa-fw fa-refresh"></i> Build index
</a>
</div>
</div>
</div>
</div>
<div class="col-xs-12 col-md-6 pf-landing-pricing-panel">
{* Cache *}
<div class="panel panel-default pricing-big">
<div class="panel-heading text-left">
<h3 class="panel-title">Cache
<span class="pull-right">
<h3 class="panel-title">Files cache
<kbd class="pull-right">
<check if="{{ @cacheSize.all }}">
<true>
{{ @cacheSize.all }}&nbsp;
@@ -766,16 +808,15 @@
0 KB&nbsp;
</false>
</check>
</span>
</kbd>
</h3>
</div>
<div class="panel-body no-padding">
<div class="btn-group btn-group-justified">
<span class="btn btn-default disabled btn-fake">
Data
<span class="pull-right">
<kbd class="pull-right">
<check if="{{ @cacheSize.data }}">
<true>
{{ @cacheSize.data }}
@@ -784,10 +825,9 @@
0 KB
</false>
</check>
</span>
</kbd>
</span>
<a href="?clearCache=1" class="btn btn-warning {{ (@cacheSize.data) ?'':'disabled' }}" role="button">
<a href="?clearCache=1#pf-setup-administration" class="btn btn-warning {{ (@cacheSize.data) ?'':'disabled' }}" role="button">
<i class="fa fa-fw fa-times"></i> Clear
</a>
</div>
@@ -795,7 +835,7 @@
<div class="btn-group btn-group-justified">
<span class="btn btn-default disabled btn-fake">
Template
<span class="pull-right">
<kbd class="pull-right">
<check if="{{ @cacheSize.template }}">
<true>
{{ @cacheSize.template }}
@@ -804,7 +844,7 @@
0 KB
</false>
</check>
</span>
</kbd>
</span>
<span class="btn btn-default disabled btn-fake"></span>
</div>

View File

@@ -32,7 +32,9 @@ input, select{
.btn-fake{
border: none;
text-align: left;
color: $gray-lighter !important;
cursor: default;
opacity: 1 !important;
color: $gray-light !important;
background-color: $gray !important;
}