try storing app in apcu

This commit is contained in:
zebardy 2019-11-18 22:07:52 +00:00
parent 75a3c6c62e
commit 06e210a0b9
5 changed files with 45 additions and 27 deletions

54
app.php
View File

@ -49,30 +49,36 @@ if (GROCY_DISABLE_AUTH === true)
} }
} }
// Setup base application if (!apcu_exists("grocy_app"))
$appContainer = new \Slim\Container([ {
'settings' => [
'displayErrorDetails' => true, // Setup base application
'determineRouteBeforeAppMiddleware' => true $appContainer = new \Slim\Container([
], 'settings' => [
'view' => function($container) 'displayErrorDetails' => true,
{ 'determineRouteBeforeAppMiddleware' => true
return new \Slim\Views\Blade(__DIR__ . '/views', GROCY_DATAPATH . '/viewcache'); ],
}, 'view' => function($container)
'LoginControllerInstance' => function($container) {
{ return new \Slim\Views\Blade(__DIR__ . '/views', GROCY_DATAPATH . '/viewcache');
return new LoginController($container, 'grocy_session'); },
}, 'LoginControllerInstance' => function($container)
'UrlManager' => function($container) {
{ return new LoginController($container, 'grocy_session');
return new UrlManager(GROCY_BASE_URL); },
}, 'UrlManager' => function($container)
'ApiKeyHeaderName' => function($container) {
{ return new UrlManager(GROCY_BASE_URL);
return 'GROCY-API-KEY'; },
} 'ApiKeyHeaderName' => function($container)
]); {
$app = new \Slim\App($appContainer); return 'GROCY-API-KEY';
}
]);
apcu_store("grocy_app", new \Slim\App($appContainer));
}
$app = apcu_fetch("grocy_app");
#$fp = fopen('/www/data/sql.log', 'a'); #$fp = fopen('/www/data/sql.log', 'a');
#fwrite($fp, "!!!Starting up loading app\n"); #fwrite($fp, "!!!Starting up loading app\n");

View File

@ -11,7 +11,7 @@ class LoginController extends BaseController
public function __construct(\Slim\Container $container, string $sessionCookieName) public function __construct(\Slim\Container $container, string $sessionCookieName)
{ {
parent::__construct($container); parent::__construct($container);
$this->SessionService = new SessionService(); $this->SessionService = SessionService::getInstance();
$this->SessionCookieName = $sessionCookieName; $this->SessionCookieName = $sessionCookieName;
} }

View File

@ -33,7 +33,7 @@ class ApiKeyAuthMiddleware extends BaseMiddleware
$validApiKey = true; $validApiKey = true;
$usedApiKey = null; $usedApiKey = null;
$sessionService = new SessionService(); $sessionService = SessionService::getInstance();
if (!isset($_COOKIE[$this->SessionCookieName]) || !$sessionService->IsValidSession($_COOKIE[$this->SessionCookieName])) if (!isset($_COOKIE[$this->SessionCookieName]) || !$sessionService->IsValidSession($_COOKIE[$this->SessionCookieName]))
{ {
$validSession = false; $validSession = false;

View File

@ -19,7 +19,7 @@ class SessionAuthMiddleware extends BaseMiddleware
{ {
$route = $request->getAttribute('route'); $route = $request->getAttribute('route');
$routeName = $route->getName(); $routeName = $route->getName();
$sessionService = new SessionService(); $sessionService = SessionService::getInstance();
if ($routeName === 'root') if ($routeName === 'root')
{ {

View File

@ -4,6 +4,18 @@ namespace Grocy\Services;
class SessionService extends BaseService class SessionService extends BaseService
{ {
private static $instance = null;
public function getInstance()
{
if (self::$instance == null)
{
self::$instance = new self();
}
return self::$instance;
}
/** /**
* @return boolean * @return boolean
*/ */