Skip to content

v2.3.0

Choose a tag to compare

@paullla paullla released this 18 Nov 19:01
db22955

v2.3.0 makes ordering and searching by translated fields faster on large collections. There are no breaking changes and no deprecations.

Highlights

Faster ordering by translated fields (#93)

TranslationOrderFilter and TranslationSearchFilter no longer join the to-many translations association. Ordering joins the translation of the current locale directly, and searching uses an EXISTS subquery. Doctrine's Paginator now runs its count and identifier queries on the tables, not on a subquery over the whole joined result.

Measured on PostgreSQL 16 with 200,000 resources and 3 locales: the count query plus the identifier query of an ordered collection went from about 1.9 seconds to about 0.3 seconds, with a unique index on the translatable and locale. With default indexes they take 0.6 to 0.75 seconds.

You do not need to change your code. For the full gain, declare the constraint the filters rely on:

#[ORM\Entity]
#[ORM\UniqueConstraint(columns: ['translatable_id', 'locale'])]
#[ORM\Index(columns: ['locale', 'title'])]
class ArticleTranslation extends AbstractTranslation
{
    // ...
}

Before you upgrade

  • Both filters now rely on one translation per resource and locale, as the indexBy: 'locale' mapping does. The unique constraint above makes the database enforce it.
  • When translations is embedded in the response and the association is not mapped EXTRA_LAZY, the current locale is no longer the first key of translations in a filtered or ordered collection. The values are the same.
  • With eager_load_translations enabled, an ordered collection still joins the translations of all locales, so its cost grows with the number of locales: 0.7 to 1.1 seconds with 10 locales on the same data. The README has the details.

Both filters stay experimental.

Package metadata (#94)

composer.json has a new description, keywords and a homepage.

Full changelog: v2.2.0...v2.3.0