Skip to content

Commit 9dd4ea2

Browse files
committed
Add unique index for background job identifier
1 parent e24afaf commit 9dd4ea2

4 files changed

Lines changed: 30 additions & 3 deletions

File tree

com.woltlab.wcf/package.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252

5353
<!--
5454
Required order of the following steps for the update to 6.2:
55+
<instruction type="script">acp/update_com.woltlab.wcf_6.2_backgroundJob.php</instruction>
5556
<instruction type="database" run="standalone">acp/database/update_com.woltlab.wcf_62_step1.php</instruction>
5657
<instruction type="script">acp/update_com.woltlab.wcf_6.2_contactOptions.php</instruction>
5758
<instruction type="database" run="standalone">acp/database/update_com.woltlab.wcf_62_step2.php</instruction>

wcfsetup/install/files/acp/database/update_com.woltlab.wcf_6.2_step1.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,17 @@
1010

1111
use wcf\system\database\table\column\IntDatabaseTableColumn;
1212
use wcf\system\database\table\column\MediumtextDatabaseTableColumn;
13-
use wcf\system\database\table\column\TextDatabaseTableColumn;
14-
use wcf\system\database\table\column\TinyintDatabaseTableColumn;
1513
use wcf\system\database\table\index\DatabaseTableForeignKey;
14+
use wcf\system\database\table\index\DatabaseTableIndex;
1615
use wcf\system\database\table\PartialDatabaseTable;
1716

1817
return [
18+
PartialDatabaseTable::create('wcf1_background_job')
19+
->indices([
20+
DatabaseTableIndex::create('identifier')
21+
->type(DatabaseTableIndex::UNIQUE_TYPE)
22+
->columns(['identifier']),
23+
]),
1924
PartialDatabaseTable::create('wcf1_user')
2025
->columns([
2126
IntDatabaseTableColumn::create('avatarFileID')
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
/**
4+
* This script removes duplicate background jobs.
5+
*/
6+
7+
use wcf\system\WCF;
8+
9+
$sql = "DELETE background_jobs
10+
FROM wcf1_background_job background_jobs
11+
JOIN (
12+
SELECT MIN(jobID) as keepID, identifier
13+
FROM wcf1_background_job
14+
WHERE identifier IS NOT NULL
15+
GROUP BY identifier
16+
HAVING COUNT(*) > 1
17+
) AS duplicates
18+
ON background_jobs.identifier = duplicates.identifier
19+
WHERE background_jobs.jobID <> duplicates.keepID";
20+
$statement = WCF::getDB()->prepare($sql);
21+
$statement->execute();

wcfsetup/setup/db/install.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ CREATE TABLE wcf1_background_job (
241241
time INT(10) NOT NULL,
242242
identifier VARCHAR(191) NULL,
243243

244-
KEY identifier (identifier),
244+
UNIQUE KEY identifier (identifier),
245245
KEY (status, time)
246246
);
247247

0 commit comments

Comments
 (0)