Skip to content

Commit 99b2cf8

Browse files
juliusknorrnickvergessen
authored andcommitted
Add hashed attribute column for indexed job existence check
Signed-off-by: Julius Härtl <jus@bitgrid.net>
1 parent a7eefa2 commit 99b2cf8

File tree

5 files changed

+73
-3
lines changed

5 files changed

+73
-3
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* @copyright Copyright (c) 2022 Julius Härtl <jus@bitgrid.net>
6+
*
7+
* @author Julius Härtl <jus@bitgrid.net>
8+
*
9+
* @license GNU AGPL version 3 or any later version
10+
*
11+
* This program is free software: you can redistribute it and/or modify
12+
* it under the terms of the GNU Affero General Public License as
13+
* published by the Free Software Foundation, either version 3 of the
14+
* License, or (at your option) any later version.
15+
*
16+
* This program is distributed in the hope that it will be useful,
17+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
* GNU Affero General Public License for more details.
20+
*
21+
* You should have received a copy of the GNU Affero General Public License
22+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
23+
*
24+
*/
25+
26+
namespace OC\Core\Migrations;
27+
28+
use Closure;
29+
use OCP\DB\ISchemaWrapper;
30+
use OCP\DB\Types;
31+
use OCP\IDBConnection;
32+
use OCP\Migration\IOutput;
33+
use OCP\Migration\SimpleMigrationStep;
34+
35+
class Version24000Date20211230140012 extends SimpleMigrationStep {
36+
/** @var IDBConnection */
37+
protected $connection;
38+
39+
public function __construct(IDBConnection $connection) {
40+
$this->connection = $connection;
41+
}
42+
43+
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
44+
/** @var ISchemaWrapper $schema */
45+
$schema = $schemaClosure();
46+
47+
$table = $schema->getTable('jobs');
48+
if (!$table->hasColumn('argument_hash')) {
49+
$table->addColumn('argument_hash', Types::STRING, [
50+
'notnull' => false,
51+
'length' => 32,
52+
]);
53+
$table->addIndex(['class', 'argument_hash'], 'job_argument_hash');
54+
return $schema;
55+
}
56+
return null;
57+
}
58+
59+
public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) {
60+
$update = $this->connection->getQueryBuilder();
61+
62+
$update->update('jobs')
63+
->set('argument_hash', $update->func()->md5('argument'));
64+
65+
$update->executeStatement();
66+
}
67+
}

lib/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -992,6 +992,7 @@
992992
'OC\\Core\\Migrations\\Version23000Date20211203110726' => $baseDir . '/core/Migrations/Version23000Date20211203110726.php',
993993
'OC\\Core\\Migrations\\Version23000Date20211213203940' => $baseDir . '/core/Migrations/Version23000Date20211213203940.php',
994994
'OC\\Core\\Migrations\\Version24000Date20211210141942' => $baseDir . '/core/Migrations/Version24000Date20211210141942.php',
995+
'OC\\Core\\Migrations\\Version24000Date20211230140012' => $baseDir . '/core/Migrations/Version24000Date20211230140012.php',
995996
'OC\\Core\\Notification\\CoreNotifier' => $baseDir . '/core/Notification/CoreNotifier.php',
996997
'OC\\Core\\Service\\LoginFlowV2Service' => $baseDir . '/core/Service/LoginFlowV2Service.php',
997998
'OC\\DB\\Adapter' => $baseDir . '/lib/private/DB/Adapter.php',

lib/composer/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,6 +1021,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
10211021
'OC\\Core\\Migrations\\Version23000Date20211203110726' => __DIR__ . '/../../..' . '/core/Migrations/Version23000Date20211203110726.php',
10221022
'OC\\Core\\Migrations\\Version23000Date20211213203940' => __DIR__ . '/../../..' . '/core/Migrations/Version23000Date20211213203940.php',
10231023
'OC\\Core\\Migrations\\Version24000Date20211210141942' => __DIR__ . '/../../..' . '/core/Migrations/Version24000Date20211210141942.php',
1024+
'OC\\Core\\Migrations\\Version24000Date20211230140012' => __DIR__ . '/../../..' . '/core/Migrations/Version24000Date20211230140012.php',
10241025
'OC\\Core\\Notification\\CoreNotifier' => __DIR__ . '/../../..' . '/core/Notification/CoreNotifier.php',
10251026
'OC\\Core\\Service\\LoginFlowV2Service' => __DIR__ . '/../../..' . '/core/Service/LoginFlowV2Service.php',
10261027
'OC\\DB\\Adapter' => __DIR__ . '/../../..' . '/lib/private/DB/Adapter.php',

lib/private/BackgroundJob/JobList.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ public function add($job, $argument = null) {
8282
->values([
8383
'class' => $query->createNamedParameter($class),
8484
'argument' => $query->createNamedParameter($argumentJson),
85+
'argument_hash' => $query->createNamedParameter(md5($argumentJson)),
8586
'last_run' => $query->createNamedParameter(0, IQueryBuilder::PARAM_INT),
8687
'last_checked' => $query->createNamedParameter($this->timeFactory->getTime(), IQueryBuilder::PARAM_INT),
8788
]);
@@ -90,7 +91,7 @@ public function add($job, $argument = null) {
9091
->set('reserved_at', $query->expr()->literal(0, IQueryBuilder::PARAM_INT))
9192
->set('last_checked', $query->createNamedParameter($this->timeFactory->getTime(), IQueryBuilder::PARAM_INT))
9293
->where($query->expr()->eq('class', $query->createNamedParameter($class)))
93-
->andWhere($query->expr()->eq('argument', $query->createNamedParameter($argumentJson)));
94+
->andWhere($query->expr()->eq('argument_hash', $query->createNamedParameter(md5($argumentJson))));
9495
}
9596
$query->executeStatement();
9697
}
@@ -145,7 +146,7 @@ public function has($job, $argument) {
145146
$query->select('id')
146147
->from('jobs')
147148
->where($query->expr()->eq('class', $query->createNamedParameter($class)))
148-
->andWhere($query->expr()->eq('argument', $query->createNamedParameter($argument)))
149+
->andWhere($query->expr()->eq('argument_hash', $query->createNamedParameter(md5($argument))))
149150
->setMaxResults(1);
150151

151152
$result = $query->execute();

version.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
// between betas, final and RCs. This is _not_ the public version number. Reset minor/patchlevel
3131
// when updating major/minor version number.
3232

33-
$OC_Version = [24, 0, 0, 3];
33+
$OC_Version = [24, 0, 0, 4];
3434

3535
// The human readable string
3636
$OC_VersionString = '24.0.0 dev';

0 commit comments

Comments
 (0)