Skip to content

Commit 8070bb2

Browse files
authored
Add index on operationTime column of generic_data_index_queue table (#121)
1 parent 456f811 commit 8070bb2

File tree

6 files changed

+78
-0
lines changed

6 files changed

+78
-0
lines changed

config/doctrine_migrations.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
doctrine_migrations:
2+
migrations_paths:
3+
'Pimcore\Bundle\GenericDataIndexBundle\Migrations': '@PimcoreGenericDataIndexBundle/src/Migrations'

qodana.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ exclude:
3939
- name: PhpUnusedParameterInspection
4040
paths:
4141
- src/SearchIndexAdapter/OpenSearch/Search/Modifier
42+
- name: PhpMethodNamingConventionInspection
43+
paths:
44+
- src/Migrations
4245
include:
4346
- name: PhpTaintFunctionInspection
4447
- name: PhpVulnerablePathsInspection

src/DependencyInjection/PimcoreGenericDataIndexExtension.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use Symfony\Component\DependencyInjection\ContainerBuilder;
2222
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
2323
use Symfony\Component\DependencyInjection\Loader;
24+
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
2425
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
2526
use Symfony\Component\Yaml\Exception\ParseException;
2627
use Symfony\Component\Yaml\Yaml;
@@ -52,8 +53,20 @@ public function load(array $configs, ContainerBuilder $container): void
5253
$this->registerIndexServiceParams($container, $config['index_service']);
5354
}
5455

56+
/**
57+
* @throws Exception
58+
*/
5559
public function prepend(ContainerBuilder $container): void
5660
{
61+
if ($container->hasExtension('doctrine_migrations')) {
62+
$loader = new YamlFileLoader(
63+
$container,
64+
new FileLocator(__DIR__ . '/../../config')
65+
);
66+
67+
$loader->load('doctrine_migrations.yaml');
68+
}
69+
5770
$filename = __DIR__ . '/../../config/doctrine.yaml';
5871

5972
try {

src/Entity/IndexQueue.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#[Entity]
2020
#[ORM\Table(name: self::TABLE)]
2121
#[ORM\Index(columns: ['dispatched'], name: self::TABLE . '_dispatched')]
22+
#[ORM\Index(columns: ['operationTime'], name: self::TABLE . '_operation_time')]
2223

2324
/**
2425
* @internal

src/Installer.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use Doctrine\DBAL\Schema\SchemaException;
2222
use Pimcore;
2323
use Pimcore\Bundle\GenericDataIndexBundle\Entity\IndexQueue;
24+
use Pimcore\Bundle\GenericDataIndexBundle\Migrations\Version20240325081139;
2425
use Pimcore\Extension\Bundle\Installer\Exception\InstallationException;
2526
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
2627

@@ -37,6 +38,11 @@ public function __construct(
3738
parent::__construct($bundle);
3839
}
3940

41+
public function getLastMigrationVersionClassName(): ?string
42+
{
43+
return Version20240325081139::class;
44+
}
45+
4046
/**
4147
* @throws SchemaException|Exception
4248
*/
@@ -96,6 +102,7 @@ private function installIndexQueueTable(Schema $schema): void
96102

97103
$queueTable->setPrimaryKey(['elementId', 'elementType']);
98104
$queueTable->addIndex(['dispatched'], IndexQueue::TABLE . '_dispatched');
105+
$queueTable->addIndex(['operationTime'], IndexQueue::TABLE . '_operation_time');
99106
}
100107
}
101108

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* Pimcore
7+
*
8+
* This source file is available under following license:
9+
* - Pimcore Commercial License (PCL)
10+
*
11+
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
12+
* @license http://www.pimcore.org/license PCL
13+
*/
14+
15+
namespace Pimcore\Bundle\GenericDataIndexBundle\Migrations;
16+
17+
use Doctrine\DBAL\Schema\Schema;
18+
use Doctrine\Migrations\AbstractMigration;
19+
use Pimcore\Bundle\GenericDataIndexBundle\Entity\IndexQueue;
20+
21+
/**
22+
* Auto-generated Migration: Please modify to your needs!
23+
*/
24+
final class Version20240325081139 extends AbstractMigration
25+
{
26+
public function getDescription(): string
27+
{
28+
return 'Add index on operationTime column in generic_data_index_queue table';
29+
}
30+
31+
public function up(Schema $schema): void
32+
{
33+
$indexName = IndexQueue::TABLE . '_operation_time';
34+
if (!$schema->getTable(IndexQueue::TABLE)->hasIndex($indexName)) {
35+
$this->addSql('ALTER TABLE `' . IndexQueue::TABLE . '`
36+
ADD INDEX `' . $indexName . '` (`operationTime`)
37+
;');
38+
}
39+
}
40+
41+
public function down(Schema $schema): void
42+
{
43+
$indexName = IndexQueue::TABLE . '_operation_time';
44+
if ($schema->getTable(IndexQueue::TABLE)->hasIndex($indexName)) {
45+
$this->addSql('ALTER TABLE `' . IndexQueue::TABLE . '`
46+
DROP INDEX `' . $indexName . '`
47+
;');
48+
}
49+
50+
}
51+
}

0 commit comments

Comments
 (0)