diff --git a/Content/Infrastructure/Doctrine/MetadataLoader.php b/Content/Infrastructure/Doctrine/MetadataLoader.php index 6d460b30..39c025e0 100644 --- a/Content/Infrastructure/Doctrine/MetadataLoader.php +++ b/Content/Infrastructure/Doctrine/MetadataLoader.php @@ -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; @@ -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)) { @@ -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)) { @@ -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']); } } @@ -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(); diff --git a/UPGRADE.md b/UPGRADE.md index 594ec93e..df6a4642 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -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 _content (stage, locale); +CREATE INDEX idx_template_key ON _content (templateKey); +CREATE INDEX idx_workflow_place ON _content (workflowPlace); +CREATE INDEX idx_workflow_published ON _content (workflowPublished); +``` + ## 0.6.0 ### Adjusted ContentDataMapper to accept DimensionContentCollection instead of separate objects