mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: registration fails with timeout on gravatar
This commit is contained in:
18
app/jobs/regular/update_gravatar.rb
Normal file
18
app/jobs/regular/update_gravatar.rb
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
module Jobs
|
||||||
|
|
||||||
|
class UpdateGravatar < Jobs::Base
|
||||||
|
|
||||||
|
def execute(args)
|
||||||
|
user = User.find_by(id: args[:user_id])
|
||||||
|
avatar = UserAvatar.find_by(id: args[:avatar_id])
|
||||||
|
|
||||||
|
if user && avatar
|
||||||
|
avatar.update_gravatar!
|
||||||
|
if !user.uploaded_avatar_id && avatar.gravatar_upload_id
|
||||||
|
user.update_column(:uploaded_avatar_id, avatar.gravatar_upload_id)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
@@ -638,15 +638,9 @@ class User < ActiveRecord::Base
|
|||||||
return if @import_mode
|
return if @import_mode
|
||||||
|
|
||||||
avatar = user_avatar || create_user_avatar
|
avatar = user_avatar || create_user_avatar
|
||||||
gravatar_downloaded = false
|
|
||||||
|
|
||||||
if SiteSetting.automatically_download_gravatars? && !avatar.last_gravatar_download_attempt
|
if SiteSetting.automatically_download_gravatars? && !avatar.last_gravatar_download_attempt
|
||||||
avatar.update_gravatar!
|
Jobs.enqueue(:update_gravatar, user_id: self.id, avatar_id: avatar.id)
|
||||||
gravatar_downloaded = avatar.gravatar_upload_id
|
|
||||||
end
|
|
||||||
|
|
||||||
if !self.uploaded_avatar_id && gravatar_downloaded
|
|
||||||
self.update_column(:uploaded_avatar_id, avatar.gravatar_upload_id)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
require_dependency 'letter_avatar'
|
require_dependency 'letter_avatar'
|
||||||
|
|
||||||
class UserAvatar < ActiveRecord::Base
|
class UserAvatar < ActiveRecord::Base
|
||||||
MAX_SIZE = 240
|
|
||||||
|
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
belongs_to :gravatar_upload, class_name: 'Upload', dependent: :destroy
|
belongs_to :gravatar_upload, class_name: 'Upload', dependent: :destroy
|
||||||
belongs_to :custom_upload, class_name: 'Upload', dependent: :destroy
|
belongs_to :custom_upload, class_name: 'Upload', dependent: :destroy
|
||||||
|
|||||||
21
spec/jobs/update_gravatar_spec.rb
Normal file
21
spec/jobs/update_gravatar_spec.rb
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe Jobs::UpdateGravatar do
|
||||||
|
|
||||||
|
it "picks gravatar if system avatar is picked and gravatar was just downloaded" do
|
||||||
|
user = User.create!(username: "bob", name: "bob", email: "a@a.com")
|
||||||
|
user.uploaded_avatar_id.should == nil
|
||||||
|
user.user_avatar.gravatar_upload_id.should == nil
|
||||||
|
|
||||||
|
png = Base64.decode64("R0lGODlhAQABALMAAAAAAIAAAACAAICAAAAAgIAAgACAgMDAwICAgP8AAAD/AP//AAAA//8A/wD//wBiZCH5BAEAAA8ALAAAAAABAAEAAAQC8EUAOw==")
|
||||||
|
FakeWeb.register_uri(:get, "http://www.gravatar.com/avatar/d10ca8d11301c2f4993ac2279ce4b930.png?s=500&d=404", body: png)
|
||||||
|
|
||||||
|
SiteSetting.automatically_download_gravatars = true
|
||||||
|
|
||||||
|
user.refresh_avatar
|
||||||
|
user.reload
|
||||||
|
|
||||||
|
user.uploaded_avatar_id.should == user.user_avatar.gravatar_upload_id
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
@@ -1094,7 +1094,6 @@ describe User do
|
|||||||
|
|
||||||
describe "automatic avatar creation" do
|
describe "automatic avatar creation" do
|
||||||
it "sets a system avatar for new users" do
|
it "sets a system avatar for new users" do
|
||||||
SiteSetting.enable_system_avatars = true
|
|
||||||
u = User.create!(username: "bob", email: "bob@bob.com")
|
u = User.create!(username: "bob", email: "bob@bob.com")
|
||||||
u.reload
|
u.reload
|
||||||
u.uploaded_avatar_id.should == nil
|
u.uploaded_avatar_id.should == nil
|
||||||
@@ -1128,30 +1127,14 @@ describe User do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe "refresh_avatar" do
|
describe "refresh_avatar" do
|
||||||
it "picks gravatar if system avatar is picked and gravatar was just downloaded" do
|
it "enqueues the update_gravatar job when automatically downloading gravatars" do
|
||||||
|
|
||||||
png = Base64.decode64("R0lGODlhAQABALMAAAAAAIAAAACAAICAAAAAgIAAgACAgMDAwICAgP8AAAD/AP//AAAA//8A/wD//wBiZCH5BAEAAA8ALAAAAAABAAEAAAQC8EUAOw==")
|
|
||||||
FakeWeb.register_uri( :get,
|
|
||||||
"http://www.gravatar.com/avatar/d10ca8d11301c2f4993ac2279ce4b930.png?s=500&d=404",
|
|
||||||
body: png )
|
|
||||||
|
|
||||||
user = User.create!(username: "bob", name: "bob", email: "a@a.com")
|
|
||||||
user.reload
|
|
||||||
|
|
||||||
SiteSetting.automatically_download_gravatars = true
|
SiteSetting.automatically_download_gravatars = true
|
||||||
SiteSetting.enable_system_avatars = true
|
|
||||||
|
user = Fabricate(:user)
|
||||||
|
|
||||||
|
Jobs.expects(:enqueue).with(:update_gravatar, anything)
|
||||||
|
|
||||||
user.refresh_avatar
|
user.refresh_avatar
|
||||||
user.reload
|
|
||||||
|
|
||||||
user.user_avatar.gravatar_upload_id.should == user.uploaded_avatar_id
|
|
||||||
|
|
||||||
user.uploaded_avatar_id = nil
|
|
||||||
user.save
|
|
||||||
user.refresh_avatar
|
|
||||||
|
|
||||||
user.reload
|
|
||||||
user.uploaded_avatar_id.should == nil
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -35,8 +35,8 @@ Spork.prefork do
|
|||||||
# let's not run seed_fu every test
|
# let's not run seed_fu every test
|
||||||
SeedFu.quiet = true if SeedFu.respond_to? :quiet
|
SeedFu.quiet = true if SeedFu.respond_to? :quiet
|
||||||
|
|
||||||
SiteSetting.enable_system_avatars = false
|
|
||||||
SiteSetting.automatically_download_gravatars = false
|
SiteSetting.automatically_download_gravatars = false
|
||||||
|
|
||||||
SeedFu.seed
|
SeedFu.seed
|
||||||
|
|
||||||
RSpec.configure do |config|
|
RSpec.configure do |config|
|
||||||
@@ -90,7 +90,6 @@ Spork.prefork do
|
|||||||
end
|
end
|
||||||
|
|
||||||
# very expensive IO operations
|
# very expensive IO operations
|
||||||
SiteSetting.enable_system_avatars = false
|
|
||||||
SiteSetting.automatically_download_gravatars = false
|
SiteSetting.automatically_download_gravatars = false
|
||||||
|
|
||||||
I18n.locale = :en
|
I18n.locale = :en
|
||||||
|
|||||||
Reference in New Issue
Block a user