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
This commit is contained in:
Régis Hanol 2024-07-23 17:12:29 +02:00 committed by GitHub
parent c333e9d6e6
commit 73ce3589ad
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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