From ac36c788d764e354b9d8b9ab0bea918e04c39e32 Mon Sep 17 00:00:00 2001 From: Marcel Klehr Date: Mon, 13 May 2024 08:55:04 +0200 Subject: fix(SynchronousBackgroundJob): Only reschedule when needed Signed-off-by: Marcel Klehr --- .../TaskProcessing/SynchronousBackgroundJob.php | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/private/TaskProcessing/SynchronousBackgroundJob.php b/lib/private/TaskProcessing/SynchronousBackgroundJob.php index ee6064aa4c6..d282d21f113 100644 --- a/lib/private/TaskProcessing/SynchronousBackgroundJob.php +++ b/lib/private/TaskProcessing/SynchronousBackgroundJob.php @@ -79,7 +79,24 @@ class SynchronousBackgroundJob extends QueuedJob { } } - // Schedule again - $this->jobList->add(self::class, $argument); + $synchronousProviders = array_filter($providers, fn ($provider) => + $provider instanceof ISynchronousProvider); + $taskTypes = array_values(array_map(fn ($provider) => + $provider->getTaskTypeId(), + $synchronousProviders + )); + $taskTypesWithTasks = array_filter($taskTypes, function ($taskType) { + try { + $this->taskProcessingManager->getNextScheduledTask($taskType); + return true; + } catch (NotFoundException|Exception $e) { + return false; + } + }); + + if (count($taskTypesWithTasks) > 0) { + // Schedule again + $this->jobList->add(self::class, $argument); + } } } -- cgit v1.2.3