From c6be80a75d6fd85b63e71e09e421b50a6b9d3724 Mon Sep 17 00:00:00 2001 From: Git'Fellow <12234510+solracsf@users.noreply.github.com> Date: Fri, 9 Aug 2024 22:38:33 +0200 Subject: [PATCH 1/2] fix(jobs): Swicth to executeStatement() while deleting rows Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com> --- lib/private/BackgroundJob/JobList.php | 53 ++++++++------------------- 1 file changed, 16 insertions(+), 37 deletions(-) diff --git a/lib/private/BackgroundJob/JobList.php b/lib/private/BackgroundJob/JobList.php index b09124281ea69..44c538dbce6e9 100644 --- a/lib/private/BackgroundJob/JobList.php +++ b/lib/private/BackgroundJob/JobList.php @@ -24,27 +24,20 @@ use function strlen; class JobList implements IJobList { - protected IDBConnection $connection; - protected IConfig $config; - protected ITimeFactory $timeFactory; - protected LoggerInterface $logger; - - public function __construct(IDBConnection $connection, IConfig $config, ITimeFactory $timeFactory, LoggerInterface $logger) { - $this->connection = $connection; - $this->config = $config; - $this->timeFactory = $timeFactory; - $this->logger = $logger; + public function __construct( + protected IDBConnection $connection, + protected IConfig $config, + protected ITimeFactory $timeFactory, + protected LoggerInterface $logger + ) { } public function add($job, $argument = null, ?int $firstCheck = null): void { if ($firstCheck === null) { $firstCheck = $this->timeFactory->getTime(); } - if ($job instanceof IJob) { - $class = get_class($job); - } else { - $class = $job; - } + + $class = ($job instanceof IJob) ? get_class($job) : $job; $argumentJson = json_encode($argument); if (strlen($argumentJson) > 4000) { @@ -81,11 +74,7 @@ public function scheduleAfter(string $job, int $runAfter, $argument = null): voi * @param mixed $argument */ public function remove($job, $argument = null): void { - if ($job instanceof IJob) { - $class = get_class($job); - } else { - $class = $job; - } + $class = ($job instanceof IJob) ? get_class($job) : $job; $query = $this->connection->getQueryBuilder(); $query->delete('jobs') @@ -104,11 +93,11 @@ public function remove($job, $argument = null): void { $query->setMaxResults($max); do { - $deleted = $query->execute(); + $deleted = $query->executeStatement(); } while ($deleted === $max); } else { // Dont use chunked delete - let the DB handle the large row count natively - $query->execute(); + $query->executeStatement(); } } @@ -126,11 +115,7 @@ public function removeById(int $id): void { * @param mixed $argument */ public function has($job, $argument): bool { - if ($job instanceof IJob) { - $class = get_class($job); - } else { - $class = $job; - } + $class = ($job instanceof IJob) ? get_class($job) : $job; $argument = json_encode($argument); $query = $this->connection->getQueryBuilder(); @@ -149,11 +134,9 @@ public function has($job, $argument): bool { public function getJobs($job, ?int $limit, int $offset): array { $iterable = $this->getJobsIterator($job, $limit, $offset); - if (is_array($iterable)) { - return $iterable; - } else { - return iterator_to_array($iterable); - } + return (is_array($iterable)) + ? $iterable + : iterator_to_array($iterable); } /** @@ -168,11 +151,7 @@ public function getJobsIterator($job, ?int $limit, int $offset): iterable { ->setFirstResult($offset); if ($job !== null) { - if ($job instanceof IJob) { - $class = get_class($job); - } else { - $class = $job; - } + $class = ($job instanceof IJob) ? get_class($job) : $job; $query->where($query->expr()->eq('class', $query->createNamedParameter($class))); } From 2156a927a3046d248d9e2f7e3621ded845e94f45 Mon Sep 17 00:00:00 2001 From: Git'Fellow <12234510+solracsf@users.noreply.github.com> Date: Fri, 9 Aug 2024 22:47:32 +0200 Subject: [PATCH 2/2] fix: lint Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com> --- lib/private/BackgroundJob/JobList.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/private/BackgroundJob/JobList.php b/lib/private/BackgroundJob/JobList.php index 44c538dbce6e9..3978ae635f778 100644 --- a/lib/private/BackgroundJob/JobList.php +++ b/lib/private/BackgroundJob/JobList.php @@ -29,7 +29,7 @@ public function __construct( protected IConfig $config, protected ITimeFactory $timeFactory, protected LoggerInterface $logger - ) { + ) { } public function add($job, $argument = null, ?int $firstCheck = null): void {