From 5e9259812a005830664534702df0409c89494652 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Mon, 17 Jul 2023 09:39:25 +0200 Subject: [PATCH] fix: Use prefilter for delete with subquery MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- lib/Db/SessionMapper.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/Db/SessionMapper.php b/lib/Db/SessionMapper.php index 957e21d5768..c2710df3217 100644 --- a/lib/Db/SessionMapper.php +++ b/lib/Db/SessionMapper.php @@ -111,8 +111,13 @@ public function deleteInactiveWithoutSteps(?int $documentId = null): int { } $qb = $this->db->getQueryBuilder(); - $qb->delete($this->getTableName()) - ->where($qb->expr()->in('id', $qb->createFunction($selectSubQuery->getSQL()))); + $qb->delete($this->getTableName()); + if ($documentId !== null) { + $qb->where($selectSubQuery->expr()->eq('document_id', $selectSubQuery->createParameter('documentId'))); + $qb->andWhere($qb->expr()->in('id', $qb->createFunction($selectSubQuery->getSQL()))); + } else { + $qb->where($qb->expr()->in('id', $qb->createFunction($selectSubQuery->getSQL()))); + } $qb->setParameters([ 'lastContact' => time() - SessionService::SESSION_VALID_TIME, 'documentId' => $documentId,