diff options
author | James Tucker <jftucker@gmail.com> | 2022-11-09 20:49:30 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-10 05:49:30 +0100 |
commit | 78a6b871fe3dae308380ea88132ddadc86a1431e (patch) | |
tree | 355c20f14f76d034c9e2b9e90d2e9c86745d4b87 /app/models/account.rb | |
parent | 0cd0786aef140ea41aa229cd52ac67867259a3f5 (diff) |
Improve performance by avoiding regex construction (#20215)
```ruby 10.times { p /#{FOO}/.object_id } 10.times { p FOO_RE.object_id } ```
Diffstat (limited to 'app/models/account.rb')
-rw-r--r-- | app/models/account.rb | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/app/models/account.rb b/app/models/account.rb index be1968fa6..cc3a8f3df 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -64,6 +64,7 @@ class Account < ApplicationRecord USERNAME_RE = /[a-z0-9_]+([a-z0-9_\.-]+[a-z0-9_]+)?/i MENTION_RE = /(?<=^|[^\/[:word:]])@((#{USERNAME_RE})(?:@[[:word:]\.\-]+[[:word:]]+)?)/i URL_PREFIX_RE = /\Ahttp(s?):\/\/[^\/]+/ + USERNAME_ONLY_RE = /\A#{USERNAME_RE}\z/i include Attachmentable include AccountAssociations @@ -84,7 +85,7 @@ class Account < ApplicationRecord validates_with UniqueUsernameValidator, if: -> { will_save_change_to_username? } # Remote user validations - validates :username, format: { with: /\A#{USERNAME_RE}\z/i }, if: -> { !local? && will_save_change_to_username? } + validates :username, format: { with: USERNAME_ONLY_RE }, if: -> { !local? && will_save_change_to_username? } # Local user validations validates :username, format: { with: /\A[a-z0-9_]+\z/i }, length: { maximum: 30 }, if: -> { local? && will_save_change_to_username? && actor_type != 'Application' } |