Commit 06162adb5060969054b0397fe18b1fb2c8e4eb2d
Committed by
Marcos Pereira
1 parent
723a6061
Exists in
staging
and in
32 other branches
Improve register performance
- Send activation code with delayed job - Avoid unecessary user save after update person Signed-off-by: Gustavo Jaruga <darksshades@gmail.com> Signed-off-by: Marcos Ronaldo <marcos.rpj2@gmail.com>
Showing
7 changed files
with
17 additions
and
6 deletions
Show diff stats
app/models/person.rb
@@ -328,7 +328,7 @@ class Person < Profile | @@ -328,7 +328,7 @@ class Person < Profile | ||
328 | end | 328 | end |
329 | 329 | ||
330 | after_update do |person| | 330 | after_update do |person| |
331 | - person.user.save! | 331 | + person.user.save! unless person.user.changes.blank? |
332 | end | 332 | end |
333 | 333 | ||
334 | def is_admin?(environment = nil) | 334 | def is_admin?(environment = nil) |
app/models/profile.rb
@@ -692,15 +692,15 @@ private :generate_url, :url_options | @@ -692,15 +692,15 @@ private :generate_url, :url_options | ||
692 | after_create :insert_default_article_set | 692 | after_create :insert_default_article_set |
693 | def insert_default_article_set | 693 | def insert_default_article_set |
694 | if template | 694 | if template |
695 | - copy_articles_from template | 695 | + self.save! if copy_articles_from template |
696 | else | 696 | else |
697 | default_set_of_articles.each do |article| | 697 | default_set_of_articles.each do |article| |
698 | article.profile = self | 698 | article.profile = self |
699 | article.advertise = false | 699 | article.advertise = false |
700 | article.save! | 700 | article.save! |
701 | end | 701 | end |
702 | + self.save! | ||
702 | end | 703 | end |
703 | - self.save! | ||
704 | end | 704 | end |
705 | 705 | ||
706 | # Override this method in subclasses of Profile to create a default article | 706 | # Override this method in subclasses of Profile to create a default article |
@@ -721,10 +721,12 @@ private :generate_url, :url_options | @@ -721,10 +721,12 @@ private :generate_url, :url_options | ||
721 | end | 721 | end |
722 | 722 | ||
723 | def copy_articles_from other | 723 | def copy_articles_from other |
724 | + return false if other.top_level_articles.empty? | ||
724 | other.top_level_articles.each do |a| | 725 | other.top_level_articles.each do |a| |
725 | copy_article_tree a | 726 | copy_article_tree a |
726 | end | 727 | end |
727 | self.articles.reload | 728 | self.articles.reload |
729 | + true | ||
728 | end | 730 | end |
729 | 731 | ||
730 | def copy_article_tree(article, parent=nil) | 732 | def copy_article_tree(article, parent=nil) |
app/models/user.rb
@@ -445,7 +445,7 @@ class User < ActiveRecord::Base | @@ -445,7 +445,7 @@ class User < ActiveRecord::Base | ||
445 | 445 | ||
446 | def deliver_activation_code | 446 | def deliver_activation_code |
447 | return if person.is_template? | 447 | return if person.is_template? |
448 | - UserMailer.activation_code(self).deliver unless self.activation_code.blank? | 448 | + Delayed::Job.enqueue(UserMailer::Job.new(self, :activation_code)) unless self.activation_code.blank? |
449 | end | 449 | end |
450 | 450 | ||
451 | def delay_activation_check | 451 | def delay_activation_check |
features/signup.feature
@@ -16,6 +16,7 @@ Feature: signup | @@ -16,6 +16,7 @@ Feature: signup | ||
16 | | Full name | José da Silva | | 16 | | Full name | José da Silva | |
17 | And wait for the captcha signup time | 17 | And wait for the captcha signup time |
18 | And I press "Create my account" | 18 | And I press "Create my account" |
19 | + And there are no pending jobs | ||
19 | Then I should receive an e-mail on josesilva@example.com | 20 | Then I should receive an e-mail on josesilva@example.com |
20 | When I go to login page | 21 | When I go to login page |
21 | And I fill in "Username" with "josesilva" | 22 | And I fill in "Username" with "josesilva" |
test/functional/search_controller_test.rb
@@ -27,6 +27,7 @@ class SearchControllerTest < ActionController::TestCase | @@ -27,6 +27,7 @@ class SearchControllerTest < ActionController::TestCase | ||
27 | # By pass user validation on person creation | 27 | # By pass user validation on person creation |
28 | user = mock() | 28 | user = mock() |
29 | user.stubs(:id).returns(1) | 29 | user.stubs(:id).returns(1) |
30 | + user.stubs(:changes).returns(nil) | ||
30 | user.stubs(:valid?).returns(true) | 31 | user.stubs(:valid?).returns(true) |
31 | user.stubs(:email).returns('some@test.com') | 32 | user.stubs(:email).returns('some@test.com') |
32 | user.stubs(:save!).returns(true) | 33 | user.stubs(:save!).returns(true) |
test/integration/signup_test.rb
@@ -45,7 +45,7 @@ class SignupTest < ActionDispatch::IntegrationTest | @@ -45,7 +45,7 @@ class SignupTest < ActionDispatch::IntegrationTest | ||
45 | assert_redirected_to controller: 'home', action: 'welcome' | 45 | assert_redirected_to controller: 'home', action: 'welcome' |
46 | 46 | ||
47 | assert_equal count + 1, User.count | 47 | assert_equal count + 1, User.count |
48 | - assert_equal mail_count + 1, ActionMailer::Base.deliveries.count | 48 | + assert_includes Delayed::Job.all.map{|d|d.name}, 'UserMailer::Job' |
49 | 49 | ||
50 | end | 50 | end |
51 | 51 |
test/unit/person_test.rb
@@ -1937,11 +1937,18 @@ class PersonTest < ActiveSupport::TestCase | @@ -1937,11 +1937,18 @@ class PersonTest < ActiveSupport::TestCase | ||
1937 | 1937 | ||
1938 | should 'a person follows many articles' do | 1938 | should 'a person follows many articles' do |
1939 | person = create_user('article_follower').person | 1939 | person = create_user('article_follower').person |
1940 | - | 1940 | + |
1941 | 1.upto(10).map do |n| | 1941 | 1.upto(10).map do |n| |
1942 | person.following_articles << fast_create(Article, :profile_id => fast_create(Person)) | 1942 | person.following_articles << fast_create(Article, :profile_id => fast_create(Person)) |
1943 | end | 1943 | end |
1944 | assert_equal 10, person.following_articles.count | 1944 | assert_equal 10, person.following_articles.count |
1945 | end | 1945 | end |
1946 | 1946 | ||
1947 | + should 'not save user after an update on person and user is not touched' do | ||
1948 | + user = create_user('testuser') | ||
1949 | + person = user.person | ||
1950 | + person.user.expects(:save!).never | ||
1951 | + person.save! | ||
1952 | + end | ||
1953 | + | ||
1947 | end | 1954 | end |