- New "Sovereignty" and "Faction warfare" data added, closed #853

- New ESI data import for wormhole type data from _ESI_, closed #852
- New ESI data import static wormholes, closed #852
- Improved performance for character authorization (PHP). Reduced number of _SQL_ queries.
- Improved HTTP cache header for `api/map/initData`, 'api/user/getEveServerStatus' ajax requests
This commit is contained in:
Mark Friedrich
2019-09-10 18:14:53 +02:00
parent a16d5c1c2b
commit d45fa9b527
108 changed files with 6946 additions and 1226 deletions

View File

@@ -16,6 +16,7 @@ use lib\db\SQL;
use lib\Resource;
use lib\Monolog;
use lib\Util;
use Model\AbstractModel;
use Model\Pathfinder;
use DB;
@@ -381,13 +382,14 @@ class Controller {
}
/**
* get current character data from session
* @return array
* get current character from session data
* @param int $ttl
* @return Pathfinder\CharacterModel|null
* @throws \Exception
*/
public function getSessionCharacterData() : array {
$data = [];
if($user = $this->getUser()){
protected function getSessionCharacter(int $ttl = AbstractModel::DEFAULT_SQL_TTL) : ?Pathfinder\CharacterModel {
$character = null;
if($user = $this->getUser($ttl)){
$header = self::getRequestHeaders();
$requestedCharacterId = (int)$header['Pf-Character'];
if( !$this->getF3()->get('AJAX') ){
@@ -400,10 +402,10 @@ class Controller {
}
}
$data = $user->getSessionCharacterData($requestedCharacterId);
$character = $user->getSessionCharacter($requestedCharacterId, $ttl);
}
return $data;
return $character;
}
/**
@@ -412,24 +414,8 @@ class Controller {
* @return Pathfinder\CharacterModel|null
* @throws \Exception
*/
public function getCharacter(int $ttl = 0) : ?Pathfinder\CharacterModel {
$character = null;
if(!empty($characterData = $this->getSessionCharacterData())){
/**
* @var $characterModel Pathfinder\CharacterModel
*/
$characterModel = Pathfinder\AbstractPathfinderModel::getNew('CharacterModel');
$characterModel->getById((int)$characterData['ID'], $ttl);
if(
!$characterModel->dry() &&
$characterModel->hasUserCharacter()
){
$character = &$characterModel;
}
}
return $character;
public function getCharacter(int $ttl = AbstractModel::DEFAULT_SQL_TTL) : ?Pathfinder\CharacterModel {
return $this->getSessionCharacter($ttl);
}
/**
@@ -438,7 +424,7 @@ class Controller {
* @return Pathfinder\UserModel|null
* @throws \Exception
*/
public function getUser($ttl = 0) : ?Pathfinder\UserModel {
public function getUser($ttl = AbstractModel::DEFAULT_SQL_TTL) : ?Pathfinder\UserModel {
$user = null;
if($this->getF3()->exists(Api\User::SESSION_KEY_USER_ID, $userId)){
@@ -452,7 +438,7 @@ class Controller {
!$userModel->dry() &&
$userModel->hasUserCharacters()
){
$user = &$userModel;
$user = $userModel;
}
}
@@ -534,10 +520,11 @@ class Controller {
* @throws \Exception
*/
public function getEveServerStatus(\Base $f3){
$ttl = 60;
$esiStatusVersion = 'latest';
$cacheKey = 'eve_server_status';
if( !$f3->exists($cacheKey, $return) ){
if(!$exists = $f3->exists($cacheKey, $return)){
$return = (object) [];
$return->error = [];
@@ -593,10 +580,10 @@ class Controller {
// find top status
$status = 'OK';
$color = 'green';
foreach($apiStatus['status'] as $statusData){
foreach($apiStatus['status'] as &$statusData){
if('red' == $statusData['status']){
$status = 'unstable';
$color = $statusData['status'];
$color = $statusData['status'] = 'orange'; // red is already in use for fatal API errors (e.g. no response at all, or offline)
break;
}
if('yellow' == $statusData['status']){
@@ -613,11 +600,15 @@ class Controller {
}
if(empty($return->error)){
$f3->set($cacheKey, $return, 60);
$f3->set($cacheKey, $return, $ttl);
}
}
}
if(empty($return->error)){
$f3->expire(Config::ttlLeft($exists, $ttl));
}
echo json_encode($return);
}