diff --git a/app/main/controller/api/setup.php b/app/main/controller/api/setup.php index 3a5d45ba..52336a0a 100644 --- a/app/main/controller/api/setup.php +++ b/app/main/controller/api/setup.php @@ -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; diff --git a/app/main/controller/ccp/universe.php b/app/main/controller/ccp/universe.php index bc33e0f7..c5f08128 100644 --- a/app/main/controller/ccp/universe.php +++ b/app/main/controller/ccp/universe.php @@ -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; } /** diff --git a/app/main/controller/setup.php b/app/main/controller/setup.php index ecf4693b..ec08ce9d 100644 --- a/app/main/controller/setup.php +++ b/app/main/controller/setup.php @@ -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' => [ diff --git a/js/app/setup.js b/js/app/setup.js index 8de203c6..2c539222 100644 --- a/js/app/setup.js +++ b/js/app/setup.js @@ -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 diff --git a/public/js/v1.4.1/app/setup.js b/public/js/v1.4.1/app/setup.js index 8de203c6..2c539222 100644 --- a/public/js/v1.4.1/app/setup.js +++ b/public/js/v1.4.1/app/setup.js @@ -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