Skip to content

A platform for community discussion. Free, open, simple.

FIX: reset gravatar cache by adding random param to URL (#9370)

Krzysztof Kotlareka81197602304
diff --git a/app/models/user_avatar.rb b/app/models/user_avatar.rb
index c3df573c324..f6dbf133126 100644
--- a/app/models/user_avatar.rb
+++ b/app/models/user_avatar.rb
@@ -20,7 +20,7 @@ class UserAvatar < ActiveRecord::Base
return if user.blank? || user.primary_email.blank?
email_hash = user_id == Discourse::SYSTEM_USER_ID ? User.email_hash("[email protected]") : user.email_hash
- gravatar_url = "https://#{SiteSetting.gravatar_base_url}/avatar/#{email_hash}.png?s=#{max}&d=404"
+ gravatar_url = "https://#{SiteSetting.gravatar_base_url}/avatar/#{email_hash}.png?s=#{max}&d=404&reset_cache=#{SecureRandom.urlsafe_base64(5)}"
# follow redirects in case gravatar change rules on us
tempfile = FileHelper.download(
diff --git a/spec/models/user_avatar_spec.rb b/spec/models/user_avatar_spec.rb
index b4e6a5468b0..c2434f1d09b 100644
--- a/spec/models/user_avatar_spec.rb
+++ b/spec/models/user_avatar_spec.rb
@@ -99,10 +99,10 @@ describe UserAvatar do
describe "404 should be silent, nothing to do really" do
it "does nothing when avatar is 404" do
-
+ SecureRandom.stubs(:urlsafe_base64).returns("5555")
freeze_time Time.now
- stub_request(:get, "https://www.gravatar.com/avatar/#{avatar.user.email_hash}.png?d=404&s=360").
+ stub_request(:get, "https://www.gravatar.com/avatar/#{avatar.user.email_hash}.png?d=404&reset_cache=5555&s=360").
to_return(status: 404, body: "", headers: {})
expect do