Skip to content

Commit fee2751

Browse files
authored
perf: Translation Memory and Tolgee AI Translator suggestion performance (tolgee#2459)
1 parent e346b5f commit fee2751

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

backend/data/src/main/kotlin/io/tolgee/service/translation/TranslationMemoryService.kt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,15 @@ class TranslationMemoryService(
8383
target.text <> '' and
8484
target.text is not null
8585
join key targetKey on target.key_id = targetKey.id
86-
where baseTranslation.language_id = p.base_language_id and
87-
(cast(:key as bigint) is null or targetKey.id <> :key) and targetKey.is_plural = :isPlural
88-
and baseTranslation.text % :baseTranslationText
86+
""" +
87+
88+
// we use the case when syntax to force postgres to evaluate all the other conditions first,
89+
// the similarity condition is slow even it uses index, and it tends to be evaluated first since
90+
// huge underestimation
91+
"""
92+
where case when (baseTranslation.language_id = p.base_language_id and
93+
(cast(:key as bigint) is null or targetKey.id <> :key) and targetKey.is_plural = :isPlural)
94+
then baseTranslation.text % :baseTranslationText end
8995
) select base.*, count(*) over()
9096
from base
9197
order by base.similarity desc

0 commit comments

Comments
 (0)