Skip to content

Commit

Permalink
perf: Translation Memory and Tolgee AI Translator suggestion performance
Browse files Browse the repository at this point in the history
  • Loading branch information
JanCizmar committed Sep 11, 2024
1 parent e346b5f commit 121ebab
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,15 @@ class TranslationMemoryService(
target.text <> '' and
target.text is not null
join key targetKey on target.key_id = targetKey.id
where baseTranslation.language_id = p.base_language_id and
(cast(:key as bigint) is null or targetKey.id <> :key) and targetKey.is_plural = :isPlural
and baseTranslation.text % :baseTranslationText
""" +

// we use the case when syntax to force postgres to evaluate all the other conditions first,
// the similarity condition is slow even it uses index, and it tends to be evaluated first since
// huge underestimation
"""
where case when (baseTranslation.language_id = p.base_language_id and
(cast(:key as bigint) is null or targetKey.id <> :key) and targetKey.is_plural = :isPlural)
then baseTranslation.text % :baseTranslationText end
) select base.*, count(*) over()
from base
order by base.similarity desc
Expand Down

0 comments on commit 121ebab

Please sign in to comment.