optimize sql queries / indexing

Signed-off-by: chandi Langecker <git@chandi.it>
This commit is contained in:
chandi Langecker
2022-09-05 13:56:15 +02:00
parent b3d4ac5218
commit af134959ce
2 changed files with 7 additions and 5 deletions

View File

@@ -38,9 +38,7 @@ class SessionMapper extends QBMapper {
$qb = $this->db->getQueryBuilder();
$result = $qb->select('*')
->from($this->getTableName())
->where($qb->expr()->eq('board_id', $qb->createNamedParameter($boardId)))
->andWhere($qb->expr()->eq('user_id', $qb->createNamedParameter($userId)))
->andWhere($qb->expr()->eq('token', $qb->createNamedParameter($token)))
->where($qb->expr()->eq('token', $qb->createNamedParameter($token)))
->andWhere($qb->expr()->gt('last_contact', $qb->createNamedParameter(time() - SessionService::SESSION_VALID_TIME)))
->executeQuery();
@@ -49,7 +47,11 @@ class SessionMapper extends QBMapper {
if ($data === false) {
throw new DoesNotExistException('Session is invalid');
}
return Session::fromRow($data);
$session = Session::fromRow($data);
if ($session->getUserId() != $userId || $session->getBoardId() != $boardId) {
throw new DoesNotExistException('Session is invalid');
}
return $session;
}
public function findAllActive($boardId) {

View File

@@ -58,8 +58,8 @@ class Version10900Date202206151724222 extends SimpleMigrationStep {
'unsigned' => true,
]);
$table->setPrimaryKey(['id']);
$table->addIndex(['board_id'], 'rd_session_board_id_idx');
$table->addIndex(['token'], 'rd_session_token_idx');
$table->addIndex(['last_contact'], 'ts_lastcontact');
}
return $schema;
}