Skip to content

Commit 96ee033

Browse files
authored
Translatable: Optimize indexes for better performance (#2986)
1 parent 29822c1 commit 96ee033

File tree

3 files changed

+5
-20
lines changed

3 files changed

+5
-20
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ a release.
2222
- SoftDeleteable: Add option to enable or disable handling of the `postFlush` event (#2958)
2323

2424
### Changed
25+
- Translatable: Optimized database indexes for better performance by reordering unique constraint fields and removing redundant indexes
2526
- SoftDeleteable: Handling of the `postFlush` event is now disabled by default (#2958)
2627

2728
### Fixed

src/Translatable/Document/Translation.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,14 @@
1818
*
1919
* @ODM\Document(repositoryClass="Gedmo\Translatable\Document\Repository\TranslationRepository")
2020
* @ODM\UniqueIndex(name="lookup_unique_idx", keys={
21-
* "locale": "asc",
22-
* "object_class": "asc",
2321
* "foreign_key": "asc",
24-
* "field": "asc"
25-
* })
26-
* @ODM\Index(name="translations_lookup_idx", keys={
2722
* "locale": "asc",
2823
* "object_class": "asc",
29-
* "foreign_key": "asc"
24+
* "field": "asc"
3025
* })
3126
*/
3227
#[ODM\Document(repositoryClass: TranslationRepository::class)]
33-
#[ODM\UniqueIndex(name: 'lookup_unique_idx', keys: ['locale' => 'asc', 'object_class' => 'asc', 'foreign_key' => 'asc', 'field' => 'asc'])]
34-
#[ODM\Index(name: 'translations_lookup_idx', keys: ['locale' => 'asc', 'object_class' => 'asc', 'foreign_key' => 'asc'])]
28+
#[ODM\UniqueIndex(name: 'lookup_unique_idx', keys: ['foreign_key' => 'asc', 'locale' => 'asc', 'object_class' => 'asc', 'field' => 'asc'])]
3529
class Translation extends AbstractTranslation
3630
{
3731
/*

src/Translatable/Entity/Translation.php

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,15 @@
1919
* @ORM\Table(
2020
* name="ext_translations",
2121
* options={"row_format": "DYNAMIC"},
22-
* indexes={
23-
* @ORM\Index(name="translations_lookup_idx", columns={
24-
* "locale", "object_class", "foreign_key"
25-
* }),
26-
* @ORM\Index(name="general_translations_lookup_idx", columns={
27-
* "object_class", "foreign_key"
28-
* })
29-
* },
3022
* uniqueConstraints={@ORM\UniqueConstraint(name="lookup_unique_idx", columns={
31-
* "locale", "object_class", "field", "foreign_key"
23+
* "foreign_key", "locale", "object_class", "field"
3224
* })}
3325
* )
3426
* @ORM\Entity(repositoryClass="Gedmo\Translatable\Entity\Repository\TranslationRepository")
3527
*/
3628
#[ORM\Entity(repositoryClass: TranslationRepository::class)]
3729
#[ORM\Table(name: 'ext_translations', options: ['row_format' => 'DYNAMIC'])]
38-
#[ORM\Index(name: 'translations_lookup_idx', columns: ['locale', 'object_class', 'foreign_key'])]
39-
#[ORM\Index(name: 'general_translations_lookup_idx', columns: ['object_class', 'foreign_key'])]
40-
#[ORM\UniqueConstraint(name: 'lookup_unique_idx', columns: ['locale', 'object_class', 'field', 'foreign_key'])]
30+
#[ORM\UniqueConstraint(name: 'lookup_unique_idx', columns: ['foreign_key', 'locale', 'object_class', 'field'])]
4131
class Translation extends AbstractTranslation
4232
{
4333
/*

0 commit comments

Comments
 (0)