File tree Expand file tree Collapse file tree 1 file changed +9
-3
lines changed
backend/data/src/main/kotlin/io/tolgee/service/translation Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments