Skip to content

Commit 4151fb6

Browse files
committed
Because of INSERT IGNORE INTO, filtering unique jobs already in the queue is no longer necessary.
1 parent 89f271e commit 4151fb6

File tree

1 file changed

+6
-39
lines changed

1 file changed

+6
-39
lines changed

wcfsetup/install/files/lib/system/background/BackgroundQueueHandler.class.php

Lines changed: 6 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use wcf\data\user\User;
66
use wcf\system\background\job\AbstractBackgroundJob;
77
use wcf\system\background\job\AbstractUniqueBackgroundJob;
8-
use wcf\system\database\util\PreparedStatementConditionBuilder;
98
use wcf\system\exception\ParentClassException;
109
use wcf\system\session\SessionHandler;
1110
use wcf\system\SingletonFactory;
@@ -73,52 +72,20 @@ public function enqueueAt(AbstractBackgroundJob|array $jobs, int $time): void
7372
$jobs = [$jobs];
7473
}
7574

76-
$identifiers = [];
7775
foreach ($jobs as $job) {
7876
if (!($job instanceof AbstractBackgroundJob)) {
7977
throw new ParentClassException(\get_class($job), AbstractBackgroundJob::class);
8078
}
81-
82-
if ($job instanceof AbstractUniqueBackgroundJob) {
83-
$identifiers[] = $job->identifier();
84-
}
85-
}
86-
87-
if ($identifiers !== []) {
88-
$conditions = new PreparedStatementConditionBuilder();
89-
$conditions->add("identifier IN (?)", [$identifiers]);
90-
91-
$sql = "SELECT DISTINCT identifier
92-
FROM wcf1_background_job
93-
{$conditions}";
94-
$statement = WCF::getDB()->prepare($sql);
95-
$statement->execute($conditions->getParameters());
96-
$existingJobs = $statement->fetchAll(\PDO::FETCH_COLUMN);
97-
98-
$jobs = \array_filter(
99-
$jobs,
100-
function ($job) use ($existingJobs) {
101-
if ($job instanceof AbstractUniqueBackgroundJob && \in_array($job->identifier(), $existingJobs)) {
102-
return false;
103-
}
104-
105-
return true;
106-
}
107-
);
108-
109-
if ($jobs === []) {
110-
return;
111-
}
11279
}
11380

11481
$sql = "INSERT IGNORE INTO wcf1_background_job
115-
(job, time,identifier)
116-
VALUES (?, ?, ?)";
117-
$statement = WCF::getDB()->prepare($sql);
82+
(job, time, identifier)
83+
VALUES (?, ?, ?)";
84+
$statement = WCF::getDB()->prepare($sql);
11885

119-
foreach ($jobs as $job) {
120-
$identifier = null;
121-
if ($job instanceof AbstractUniqueBackgroundJob) {
86+
foreach ($jobs as $job) {
87+
$identifier = null;
88+
if ($job instanceof AbstractUniqueBackgroundJob) {
12289
$identifier = $job->identifier();
12390
}
12491

0 commit comments

Comments
 (0)