From 73ce3589adf2b859ac5991d65ab405f280dcd292 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Tue, 23 Jul 2024 17:12:29 +0200 Subject: [PATCH] PERF: improves TextSentinel's seems_unpretentious check (#28044) by scanning the text for the first word that is bigger than `max_word_length` instead of extracting (segmenting) all the words, computing their size, and comparing the maximum with `max_word_length`. Idea from @mentalstring in https://meta.discourse.org/t/body-seems-unclear-error-when-users-are-typing-in-chinese/88715/14 --- lib/text_sentinel.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/text_sentinel.rb b/lib/text_sentinel.rb index 7e8faff8820..9ae59fd8c87 100644 --- a/lib/text_sentinel.rb +++ b/lib/text_sentinel.rb @@ -59,7 +59,7 @@ class TextSentinel # Ensure maximum word length def seems_unpretentious? skipped_locales.include?(SiteSetting.default_locale) || @opts[:max_word_length].nil? || - @text.scan(/\p{Alnum}+/).map(&:size).max.to_i <= @opts[:max_word_length] + !@text.match?(/\p{Alnum}{#{@opts[:max_word_length] + 1},}/) end # Ensure at least one lowercase letter