Skip to content

Commit

Permalink
Add indexes to improve performance of some queries
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-schranz committed Oct 3, 2022
1 parent bbe3c44 commit 639c29c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
18 changes: 18 additions & 0 deletions Content/Infrastructure/Doctrine/MetadataLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Doctrine\Inflector\InflectorFactory;
use Doctrine\ORM\Event\LoadClassMetadataEventArgs;
use Doctrine\ORM\Events;
use Doctrine\ORM\Mapping\Builder\ClassMetadataBuilder;
use Doctrine\ORM\Mapping\ClassMetadataInfo;
use Sulu\Bundle\CategoryBundle\Entity\CategoryInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentInterface;
Expand Down Expand Up @@ -47,6 +48,8 @@ public function loadClassMetadata(LoadClassMetadataEventArgs $event): void
if ($reflection->implementsInterface(DimensionContentInterface::class)) {
$this->addField($metadata, 'stage', 'string', ['length' => 16, 'nullable' => false]);
$this->addField($metadata, 'locale', 'string', ['length' => 7, 'nullable' => true]);

$this->addIndex($metadata, 'idx_dimension', ['stage', 'locale']);
}

if ($reflection->implementsInterface(SeoInterface::class)) {
Expand All @@ -62,6 +65,8 @@ public function loadClassMetadata(LoadClassMetadataEventArgs $event): void
if ($reflection->implementsInterface(TemplateInterface::class)) {
$this->addField($metadata, 'templateKey', 'string', ['length' => 32]);
$this->addField($metadata, 'templateData', 'json', ['nullable' => false]);

$this->addIndex($metadata, 'idx_template_key', ['templateKey']);
}

if ($reflection->implementsInterface(ExcerptInterface::class)) {
Expand Down Expand Up @@ -97,6 +102,9 @@ public function loadClassMetadata(LoadClassMetadataEventArgs $event): void
if ($reflection->implementsInterface(WorkflowInterface::class)) {
$this->addField($metadata, 'workflowPlace', 'string', ['length' => 32, 'nullable' => true]);
$this->addField($metadata, 'workflowPublished', 'datetime_immutable', ['nullable' => true]);

$this->addIndex($metadata, 'idx_workflow_place', ['workflowPlace']);
$this->addIndex($metadata, 'idx_workflow_published', ['workflowPublished']);
}
}

Expand Down Expand Up @@ -194,6 +202,16 @@ private function addField(ClassMetadataInfo $metadata, string $name, string $typ
], $mapping));
}

/**
* @param \Doctrine\ORM\Mapping\ClassMetadata $metadata
*/
private function addIndex(ClassMetadataInfo $metadata, string $name, array $fields): void
{
$builder = new ClassMetadataBuilder($metadata);

$builder->addIndex($fields, $name);
}

private function getRelationTableName(ClassMetadataInfo $metadata, string $relationName): string
{
$inflector = InflectorFactory::create()->build();
Expand Down
13 changes: 13 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# Upgrade

## 0.6.3

### Add dimension, templateKey, workflowPublished and workflowPlace indexes

Improve performance of the `*ContentDimension` tables with additional indexes for the database:

```sql
CREATE INDEX idx_dimension ON <your_entity>_content (stage, locale);
CREATE INDEX idx_template_key ON <your_entity>_content (templateKey);
CREATE INDEX idx_workflow_place ON <your_entity>_content (workflowPlace);
CREATE INDEX idx_workflow_published ON <your_entity>_content (workflowPublished);
```

## 0.6.0

### Adjusted ContentDataMapper to accept DimensionContentCollection instead of separate objects
Expand Down

0 comments on commit 639c29c

Please sign in to comment.