summaryrefslogtreecommitdiff
path: root/app/helpers/avatars_helper.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-03-16 18:18:33 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2021-03-16 18:18:33 +0000
commitf64a639bcfa1fc2bc89ca7db268f594306edfd7c (patch)
treea2c3c2ebcc3b45e596949db485d6ed18ffaacfa1 /app/helpers/avatars_helper.rb
parentbfbc3e0d6583ea1a91f627528bedc3d65ba4b10f (diff)
downloadgitlab-ce-f64a639bcfa1fc2bc89ca7db268f594306edfd7c.tar.gz
Add latest changes from gitlab-org/gitlab@13-10-stable-eev13.10.0-rc40
Diffstat (limited to 'app/helpers/avatars_helper.rb')
-rw-r--r--app/helpers/avatars_helper.rb29
1 files changed, 18 insertions, 11 deletions
diff --git a/app/helpers/avatars_helper.rb b/app/helpers/avatars_helper.rb
index 5457f96d506..8d22bda279f 100644
--- a/app/helpers/avatars_helper.rb
+++ b/app/helpers/avatars_helper.rb
@@ -22,11 +22,14 @@ module AvatarsHelper
end
def avatar_icon_for_email(email = nil, size = nil, scale = 2, only_path: true)
- user = User.find_by_any_email(email)
- if user
- avatar_icon_for_user(user, size, scale, only_path: only_path)
+ return gravatar_icon(email, size, scale) if email.nil?
+
+ if Feature.enabled?(:avatar_cache_for_email, @current_user, type: :development)
+ Gitlab::AvatarCache.by_email(email, size, scale, only_path) do
+ avatar_icon_by_user_email_or_gravatar(email, size, scale, only_path: only_path)
+ end
else
- gravatar_icon(email, size, scale)
+ avatar_icon_by_user_email_or_gravatar(email, size, scale, only_path: only_path)
end
end
@@ -101,19 +104,23 @@ module AvatarsHelper
private
- def user_avatar_url_for(only_path: true, **options)
- return options[:url] if options[:url]
-
- email = options[:user_email]
- user = options.key?(:user) ? options[:user] : User.find_by_any_email(email)
+ def avatar_icon_by_user_email_or_gravatar(email, size, scale, only_path:)
+ user = User.find_by_any_email(email)
if user
- avatar_icon_for_user(user, options[:size], only_path: only_path)
+ avatar_icon_for_user(user, size, scale, only_path: only_path)
else
- gravatar_icon(email, options[:size])
+ gravatar_icon(email, size, scale)
end
end
+ def user_avatar_url_for(only_path: true, **options)
+ return options[:url] if options[:url]
+ return avatar_icon_for_user(options[:user], options[:size], only_path: only_path) if options[:user]
+
+ avatar_icon_for_email(options[:user_email], options[:size], only_path: only_path)
+ end
+
def source_icon(source, options = {})
avatar_url = source.try(:avatar_url)