Skip to content

Commit

Permalink
fix: Use prefilter for delete with subquery
Browse files Browse the repository at this point in the history
Signed-off-by: Julius Härtl <jus@bitgrid.net>
  • Loading branch information
juliushaertl committed Jul 17, 2023
1 parent db38b30 commit 6927df8
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/Db/SessionMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 6927df8

Please sign in to comment.