?
avatar Denitz
Denitz
30 Jul 2020

Is your feature request related to a problem? Please describe.

If the session handler is database, Joomla\CMS\Session\MetadataManager::checkSessionRecordExists() performs an extra database query which is is actually actually useless.

Describe the solution you'd like

This method is executed onAfterSessionStart, hence the record in #__session always exists if a session is stored in the database.

For database session storage we can omit the check for table record presence because it always exists at this stage (sure if the session is in Active state).

avatar Denitz Denitz - open - 30 Jul 2020
avatar joomla-cms-bot joomla-cms-bot - change - 30 Jul 2020
Labels Added: ?
avatar joomla-cms-bot joomla-cms-bot - labeled - 30 Jul 2020
avatar Denitz Denitz - change - 30 Jul 2020
Title
[4.0] Joomla\CMS\Session\MetadataManager::checkSessionRecordExists() extra SQL query.
[4.0] Joomla\CMS\Session\MetadataManager::checkSessionRecordExists() extra SQL query
avatar Denitz Denitz - edited - 30 Jul 2020
avatar Denitz
Denitz - comment - 30 Jul 2020

Sorry, no time for PR, here is the sample code for Joomla\CMS\Session\MetadataManager::createOrUpdateRecord()

	public function createOrUpdateRecord(SessionInterface $session, User $user)
	{
		// Active session with database storage always exists at this stage.
		if ($this->app->get('session_handler') === 'database' && $session->isActive())
		{
			$exists = self::$sessionRecordExists;
		}
		else
		{
			$exists = $this->checkSessionRecordExists($session->getId());
		}

		// Do not try to touch the database if we can't determine the record state
		if ($exists === self::$sessionRecordUnknown)
		{
			return;
		}

		if ($exists === self::$sessionRecordDoesNotExist)
		{
			$this->createSessionRecord($session, $user);

			return;
		}

		$this->updateSessionRecord($session, $user);
	}
avatar Denitz Denitz - change - 17 Nov 2020
Status New Closed
Closed_Date 0000-00-00 00:00:00 2020-11-17 08:45:35
Closed_By Denitz
avatar Denitz
Denitz - comment - 17 Nov 2020
avatar Denitz Denitz - close - 17 Nov 2020

Add a Comment

Login with GitHub to post a comment