From 087ed84367537ac168ed3e00bb7eb4bd582dc3d0 Mon Sep 17 00:00:00 2001 From: luigi <007.lva@gmail.com> Date: Sat, 9 Jan 2021 18:32:01 -0500 Subject: Optimize map { ... }.compact calls (#15513) * Optimize map { ... }.compact using Enumerable#filter_map, supported since Ruby 2.7 * Add poyfill for Enumerable#filter_map --- app/validators/existing_username_validator.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/validators') 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@/, '')) -- cgit