- fixed a bug where "build index" for systems on /setup page never ends, closed #666
This commit is contained in:
@@ -25,11 +25,13 @@ class Setup extends Controller\Controller {
|
||||
$postData = (array)$f3->get('POST');
|
||||
$type = (string)$postData['type'];
|
||||
$count = (int)$postData['count'];
|
||||
$offset = (int)$postData['offset'];
|
||||
|
||||
$return = (object) [];
|
||||
$return->error = [];
|
||||
$return->type = $type;
|
||||
$return->count = $count;
|
||||
$return->offset = $offset;
|
||||
$return->countAll = 0;
|
||||
$return->countBuild = 0;
|
||||
$return->countBuildAll = 0;
|
||||
@@ -60,12 +62,12 @@ class Setup extends Controller\Controller {
|
||||
switch($type){
|
||||
case 'Systems':
|
||||
$length = 100;
|
||||
$offset = $count * $length;
|
||||
$buildInfo = $controller->buildSystemsIndex($offset, $length);
|
||||
$return->offset = $buildInfo['offset'];
|
||||
$return->countAll = $buildInfo['countAll'];
|
||||
$return->countBuild = $buildInfo['countBuild'];
|
||||
$return->countBuildAll = count($controller->getSystemsIndex());
|
||||
$return->progress = $percent($return->countAll, $offset + $length);
|
||||
$return->countBuildAll = $offset;
|
||||
$return->progress = $percent($return->countAll, $offset);
|
||||
break;
|
||||
case 'Structures':
|
||||
$categoryId = 65;
|
||||
|
||||
@@ -14,6 +14,8 @@ use Model;
|
||||
|
||||
class Universe extends Controller {
|
||||
|
||||
const SESSION_KEY_SYSTEM_IDS = 'SESSION.SETUP.SYSTEM_IDS';
|
||||
|
||||
|
||||
/* currently not used
|
||||
protected function setupRegions(\Base $f3){
|
||||
@@ -134,21 +136,45 @@ class Universe extends Controller {
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function buildSystemsIndex(int $offset = 0, int $length = 10) : array {
|
||||
$systemIds = $this->getSystemIds();
|
||||
$systemsAll = count($systemIds);
|
||||
$systemIds = array_slice($systemIds, $offset, $length);
|
||||
|
||||
/**
|
||||
* @var $system Model\Universe\SystemModel
|
||||
*/
|
||||
$system = Model\Universe\BasicUniverseModel::getNew('SystemModel');
|
||||
$systems = $system->find();
|
||||
$systemIds = $systems->getAll('id', true);
|
||||
sort($systemIds, SORT_NUMERIC);
|
||||
$systemsAll = count($systemIds);
|
||||
$systemIds = array_slice($systemIds, $offset, $length);
|
||||
foreach($systemIds as $systemId){
|
||||
$system->getById($systemId);
|
||||
$system->buildIndex();
|
||||
$system->reset();
|
||||
$offset++;
|
||||
}
|
||||
return ['countAll' => $systemsAll, 'countBuild' => count($systemIds)];
|
||||
return ['countAll' => $systemsAll, 'countBuild' => count($systemIds), 'offset' => $offset];
|
||||
}
|
||||
|
||||
/**
|
||||
* get systemIds for all systems
|
||||
* @return array
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function getSystemIds() : array {
|
||||
$f3 = $this->getF3();
|
||||
if( !$f3->exists(self::SESSION_KEY_SYSTEM_IDS, $systemIds) ){
|
||||
/**
|
||||
* @var $system Model\Universe\SystemModel
|
||||
*/
|
||||
$system = Model\Universe\BasicUniverseModel::getNew('SystemModel');
|
||||
$systems = $system->find();
|
||||
$systemIds = $systems->getAll('id');
|
||||
|
||||
if(count($systemIds)){
|
||||
sort($systemIds, SORT_NUMERIC);
|
||||
$f3->set(self::SESSION_KEY_SYSTEM_IDS, $systemIds);
|
||||
}
|
||||
}
|
||||
|
||||
return (array)$systemIds;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1238,7 +1238,6 @@ class Setup extends Controller {
|
||||
// active DB and tables are required for obtain index data
|
||||
if(!$this->databaseHasError){
|
||||
$categoryUniverseModel = Model\Universe\BasicUniverseModel::getNew('CategoryModel');
|
||||
$systemUniverseModel = Model\Universe\BasicUniverseModel::getNew('SystemModel');
|
||||
$systemNeighbourModel = Model\BasicModel::getNew('SystemNeighbourModel');
|
||||
|
||||
$indexInfo = [
|
||||
@@ -1258,7 +1257,7 @@ class Setup extends Controller {
|
||||
],
|
||||
'label' => 'build systems index',
|
||||
'countBuild' => count((new Universe())->getSystemsIndex()),
|
||||
'countAll' => $this->dbLib->getRowCount($systemUniverseModel->getTable(), 'UNIVERSE'),
|
||||
'countAll' => count((new Universe())->getSystemIds()),
|
||||
'tooltip' => 'build up a static search index over all systems found on DB. Do not refresh page until import is complete (check progress)! Runtime: ~5min'
|
||||
],
|
||||
'Structures' => [
|
||||
|
||||
@@ -71,7 +71,8 @@ define([
|
||||
let url = '/api/setup/' + element.attr('data-action');
|
||||
sendRequest(url, {
|
||||
type: element.attr('data-type'),
|
||||
count: 0
|
||||
count: 0,
|
||||
offset: 0
|
||||
}, {
|
||||
target: element,
|
||||
url: url
|
||||
@@ -113,7 +114,8 @@ define([
|
||||
){
|
||||
sendRequest(context.url, {
|
||||
type: responseData.type,
|
||||
count: responseData.count
|
||||
count: responseData.count,
|
||||
offset: responseData.offset
|
||||
}, {
|
||||
target: context.target,
|
||||
url: context.url
|
||||
|
||||
@@ -71,7 +71,8 @@ define([
|
||||
let url = '/api/setup/' + element.attr('data-action');
|
||||
sendRequest(url, {
|
||||
type: element.attr('data-type'),
|
||||
count: 0
|
||||
count: 0,
|
||||
offset: 0
|
||||
}, {
|
||||
target: element,
|
||||
url: url
|
||||
@@ -113,7 +114,8 @@ define([
|
||||
){
|
||||
sendRequest(context.url, {
|
||||
type: responseData.type,
|
||||
count: responseData.count
|
||||
count: responseData.count,
|
||||
offset: responseData.offset
|
||||
}, {
|
||||
target: context.target,
|
||||
url: context.url
|
||||
|
||||
Reference in New Issue
Block a user