From cf8e285b622ed87deb06556482e2fd451937d0eb Mon Sep 17 00:00:00 2001 From: zebardy Date: Fri, 22 Nov 2019 16:37:13 +0000 Subject: [PATCH] in depth look at Logincontroller timings --- controllers/BaseController.php | 8 ++++++++ controllers/LoginController.php | 19 ++++++++++++++----- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/controllers/BaseController.php b/controllers/BaseController.php index fc5be2de..76dcbdc5 100644 --- a/controllers/BaseController.php +++ b/controllers/BaseController.php @@ -10,16 +10,21 @@ use \Grocy\Services\UsersService; class BaseController { public function __construct(\Slim\Container $container) { + $fp = fopen('/config/data/sql.log', 'a'); + $time_start = microtime(true); $databaseService = DatabaseService::getInstance(); $this->Database = $databaseService->GetDbConnection(); + fwrite($fp, "%%% Login controller - parent construstor database time : " . round((microtime(true) - $time_start),6) . "\n"); $localizationService = LocalizationService::getInstance(GROCY_CULTURE); $this->LocalizationService = $localizationService; + fwrite($fp, "%%% Login controller - parent construstor localisation time : " . round((microtime(true) - $time_start),6) . "\n"); $applicationService = ApplicationService::getInstance(); $versionInfo = $applicationService->GetInstalledVersion(); $container->view->set('version', $versionInfo->Version); $container->view->set('releaseDate', $versionInfo->ReleaseDate); + fwrite($fp, "%%% Login controller - parent construstor application service time : " . round((microtime(true) - $time_start),6) . "\n"); $container->view->set('__t', function(string $text, ...$placeholderValues) use($localizationService) { @@ -54,6 +59,7 @@ class BaseController $container->view->set('featureFlags', $constants); $container->view->set('userentitiesForSidebar', $this->Database->userentities()->where('show_in_sidebar_menu = 1')->orderBy('name')); + fwrite($fp, "%%% Login controller - parent construstor view time : " . round((microtime(true) - $time_start),6) . "\n"); try { @@ -73,6 +79,8 @@ class BaseController } $this->AppContainer = $container; + fwrite($fp, "%%% Login controller - parent construstor total time : " . round((microtime(true) - $time_start),6) . "\n"); + fclose($fp); } protected $AppContainer; diff --git a/controllers/LoginController.php b/controllers/LoginController.php index 7aa20708..923546ad 100644 --- a/controllers/LoginController.php +++ b/controllers/LoginController.php @@ -14,16 +14,25 @@ class LoginController extends BaseController $time_start = microtime(true); parent::__construct($container); fwrite($fp, "£££ Login controller - parent construstor time : " . round((microtime(true) - $time_start),6) . "\n"); - $this->SessionService = SessionService::getInstance(); - fwrite($fp, "£££ Login controller - got session service instance : " . round((microtime(true) - $time_start),6) . "\n"); + #$this->SessionService = SessionService::getInstance(); + #fwrite($fp, "£££ Login controller - got session service instance : " . round((microtime(true) - $time_start),6) . "\n"); $this->SessionCookieName = $sessionCookieName; fwrite($fp, "£££ Login controller - construction time : " . round((microtime(true) - $time_start),6) . "\n"); fclose($fp); } - protected $SessionService; + protected $SessionService = null; protected $SessionCookieName; + private function getSessionService() + { + if($this->SessionsService == null) + { + $this->SessionService = SessionService::getInstance(); + } + return $this->SessionService; + } + public function ProcessLogin(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args) { $fp = fopen('/config/data/sql.log', 'a'); @@ -38,7 +47,7 @@ class LoginController extends BaseController if ($user !== null && password_verify($inputPassword, $user->password)) { - $sessionKey = $this->SessionService->CreateSession($user->id, $stayLoggedInPermanently); + $sessionKey = $this->getSessionService()->CreateSession($user->id, $stayLoggedInPermanently); setcookie($this->SessionCookieName, $sessionKey, PHP_INT_SIZE == 4 ? PHP_INT_MAX : PHP_INT_MAX>>32); // Cookie expires never, but session validity is up to SessionService if (password_needs_rehash($user->password, PASSWORD_DEFAULT)) @@ -68,7 +77,7 @@ class LoginController extends BaseController public function Logout(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args) { - $this->SessionService->RemoveSession($_COOKIE[$this->SessionCookieName]); + $this->getSessionService()->RemoveSession($_COOKIE[$this->SessionCookieName]); return $response->withRedirect($this->AppContainer->UrlManager->ConstructUrl('/')); }