about summary refs log tree commit diff
path: root/app/validators
diff options
context:
space:
mode:
authorluigi <007.lva@gmail.com>2021-01-09 18:32:01 -0500
committerGitHub <noreply@github.com>2021-01-10 00:32:01 +0100
commit087ed84367537ac168ed3e00bb7eb4bd582dc3d0 (patch)
tree2374e63ef1aabe4b9991dd30c4eba8adfec89839 /app/validators
parent93951431269403201550e914dee508a522becf8b (diff)
Optimize map { ... }.compact calls (#15513)
* Optimize map { ... }.compact

using Enumerable#filter_map, supported since Ruby 2.7

* Add poyfill for Enumerable#filter_map
Diffstat (limited to 'app/validators')
-rw-r--r--app/validators/existing_username_validator.rb2
1 files changed, 1 insertions, 1 deletions
diff --git a/app/validators/existing_username_validator.rb b/app/validators/existing_username_validator.rb
index b31d09827..723302ec9 100644
--- a/app/validators/existing_username_validator.rb
+++ b/app/validators/existing_username_validator.rb
@@ -5,7 +5,7 @@ class ExistingUsernameValidator < ActiveModel::EachValidator
     return if value.blank?
 
     if options[:multiple]
-      missing_usernames = value.split(',').map { |username| username.strip.gsub(/\A@/, '') }.map { |username| username unless Account.find_local(username) }.compact
+      missing_usernames = value.split(',').map { |username| username.strip.gsub(/\A@/, '') }.filter_map { |username| username unless Account.find_local(username) }
       record.errors.add(attribute, I18n.t('existing_username_validator.not_found_multiple', usernames: missing_usernames.join(', '))) if missing_usernames.any?
     else
       record.errors.add(attribute, I18n.t('existing_username_validator.not_found')) unless Account.find_local(value.strip.gsub(/\A@/, ''))