mirror of
https://github.com/grocy/grocy.git
synced 2026-04-05 20:36:15 +02:00
try storing app in apcu
This commit is contained in:
parent
75a3c6c62e
commit
06e210a0b9
54
app.php
54
app.php
|
|
@ -49,30 +49,36 @@ if (GROCY_DISABLE_AUTH === true)
|
|||
}
|
||||
}
|
||||
|
||||
// Setup base application
|
||||
$appContainer = new \Slim\Container([
|
||||
'settings' => [
|
||||
'displayErrorDetails' => true,
|
||||
'determineRouteBeforeAppMiddleware' => true
|
||||
],
|
||||
'view' => function($container)
|
||||
{
|
||||
return new \Slim\Views\Blade(__DIR__ . '/views', GROCY_DATAPATH . '/viewcache');
|
||||
},
|
||||
'LoginControllerInstance' => function($container)
|
||||
{
|
||||
return new LoginController($container, 'grocy_session');
|
||||
},
|
||||
'UrlManager' => function($container)
|
||||
{
|
||||
return new UrlManager(GROCY_BASE_URL);
|
||||
},
|
||||
'ApiKeyHeaderName' => function($container)
|
||||
{
|
||||
return 'GROCY-API-KEY';
|
||||
}
|
||||
]);
|
||||
$app = new \Slim\App($appContainer);
|
||||
if (!apcu_exists("grocy_app"))
|
||||
{
|
||||
|
||||
// Setup base application
|
||||
$appContainer = new \Slim\Container([
|
||||
'settings' => [
|
||||
'displayErrorDetails' => true,
|
||||
'determineRouteBeforeAppMiddleware' => true
|
||||
],
|
||||
'view' => function($container)
|
||||
{
|
||||
return new \Slim\Views\Blade(__DIR__ . '/views', GROCY_DATAPATH . '/viewcache');
|
||||
},
|
||||
'LoginControllerInstance' => function($container)
|
||||
{
|
||||
return new LoginController($container, 'grocy_session');
|
||||
},
|
||||
'UrlManager' => function($container)
|
||||
{
|
||||
return new UrlManager(GROCY_BASE_URL);
|
||||
},
|
||||
'ApiKeyHeaderName' => function($container)
|
||||
{
|
||||
return 'GROCY-API-KEY';
|
||||
}
|
||||
]);
|
||||
apcu_store("grocy_app", new \Slim\App($appContainer));
|
||||
}
|
||||
|
||||
$app = apcu_fetch("grocy_app");
|
||||
|
||||
#$fp = fopen('/www/data/sql.log', 'a');
|
||||
#fwrite($fp, "!!!Starting up loading app\n");
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ class LoginController extends BaseController
|
|||
public function __construct(\Slim\Container $container, string $sessionCookieName)
|
||||
{
|
||||
parent::__construct($container);
|
||||
$this->SessionService = new SessionService();
|
||||
$this->SessionService = SessionService::getInstance();
|
||||
$this->SessionCookieName = $sessionCookieName;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ class ApiKeyAuthMiddleware extends BaseMiddleware
|
|||
$validApiKey = true;
|
||||
$usedApiKey = null;
|
||||
|
||||
$sessionService = new SessionService();
|
||||
$sessionService = SessionService::getInstance();
|
||||
if (!isset($_COOKIE[$this->SessionCookieName]) || !$sessionService->IsValidSession($_COOKIE[$this->SessionCookieName]))
|
||||
{
|
||||
$validSession = false;
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ class SessionAuthMiddleware extends BaseMiddleware
|
|||
{
|
||||
$route = $request->getAttribute('route');
|
||||
$routeName = $route->getName();
|
||||
$sessionService = new SessionService();
|
||||
$sessionService = SessionService::getInstance();
|
||||
|
||||
if ($routeName === 'root')
|
||||
{
|
||||
|
|
|
|||
|
|
@ -4,6 +4,18 @@ namespace Grocy\Services;
|
|||
|
||||
class SessionService extends BaseService
|
||||
{
|
||||
private static $instance = null;
|
||||
|
||||
public function getInstance()
|
||||
{
|
||||
if (self::$instance == null)
|
||||
{
|
||||
self::$instance = new self();
|
||||
}
|
||||
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return boolean
|
||||
*/
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user