about summary refs log tree commit diff
path: root/app/models
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2016-03-22 21:05:23 +0100
committerEugen Rochko <eugen@zeonfederated.com>2016-03-22 21:05:23 +0100
commit02e4fb2e06f424c16ab25ea294a4af6490a5f7e3 (patch)
treea63f863ed677eb789646ab468681001628e29490 /app/models
parent921f40c1873883e8ce476e04de1f3f1bd5ccbf91 (diff)
Only re-download avatar if URL changed (fix #19)
Diffstat (limited to 'app/models')
-rw-r--r--app/models/account.rb8
1 files changed, 5 insertions, 3 deletions
diff --git a/app/models/account.rb b/app/models/account.rb
index 06f858c7c..c686a47ed 100644
--- a/app/models/account.rb
+++ b/app/models/account.rb
@@ -5,7 +5,6 @@ class Account < ActiveRecord::Base
   validates :username, uniqueness: { scope: :domain, case_sensitive: true },  unless: 'local?'
 
   # Avatar upload
-  attr_reader :avatar_remote_url
   has_attached_file :avatar, styles: { large: '300x300#', medium: '96x96#', small: '48x48#' }, default_url: 'avatars/missing.png'
   validates_attachment_content_type :avatar, content_type: /\Aimage\/.*\Z/
 
@@ -91,8 +90,11 @@ class Account < ActiveRecord::Base
   end
 
   def avatar_remote_url=(url)
-    self.avatar = URI.parse(url)
-    @avatar_remote_url = url
+    unless self[:avatar_remote_url] == url
+      self.avatar = URI.parse(url)
+    end
+
+    self[:avatar_remote_url] = url
   end
 
   def to_param