mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 09:42:02 +08:00
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:
parent
c333e9d6e6
commit
73ce3589ad
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user