Improve performance by avoiding regex construction (#20215)
```ruby 10.times { p /#{FOO}/.object_id } 10.times { p FOO_RE.object_id } ```
This commit is contained in:
parent
0cd0786aef
commit
78a6b871fe
8 changed files with 21 additions and 12 deletions
|
@ -3,6 +3,8 @@
|
|||
class AccountSearchService < BaseService
|
||||
attr_reader :query, :limit, :offset, :options, :account
|
||||
|
||||
MENTION_ONLY_RE = /\A#{Account::MENTION_RE}\z/i
|
||||
|
||||
# Min. number of characters to look for non-exact matches
|
||||
MIN_QUERY_LENGTH = 5
|
||||
|
||||
|
@ -180,7 +182,7 @@ class AccountSearchService < BaseService
|
|||
end
|
||||
|
||||
def username_complete?
|
||||
query.include?('@') && "@#{query}".match?(/\A#{Account::MENTION_RE}\Z/)
|
||||
query.include?('@') && "@#{query}".match?(MENTION_ONLY_RE)
|
||||
end
|
||||
|
||||
def likely_acct?
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue