[Git][noosfero/noosfero][master] 2 commits: Improve register performance

Rodrigo Souto gitlab at mg.gitlab.com
Thu Mar 31 19:41:40 BRT 2016


Rodrigo Souto pushed to branch master at Noosfero / noosfero


Commits:
06162adb by Victor Costa at 2016-03-29T09:55:23-03:00
Improve register performance

- Send activation code with delayed job
- Avoid unecessary user save after update person

Signed-off-by: Gustavo Jaruga <darksshades at gmail.com>
Signed-off-by: Marcos Ronaldo <marcos.rpj2 at gmail.com>

- - - - -
5b115b7a by Rodrigo Souto at 2016-03-31T22:40:54+00:00
Merge branch 'master_register_performance' into 'master'

Improve register performance

- Send activation code with delayed job
- Avoid unecessary user save after update person

Signed-off-by: Gustavo Jaruga <darksshades at gmail.com>
Signed-off-by: Marcos Ronaldo <marcos.rpj2 at gmail.com>

See merge request !829
- - - - -


7 changed files:

- app/models/person.rb
- app/models/profile.rb
- app/models/user.rb
- features/signup.feature
- test/functional/search_controller_test.rb
- test/integration/signup_test.rb
- test/unit/person_test.rb


Changes:

=====================================
app/models/person.rb
=====================================
--- a/app/models/person.rb
+++ b/app/models/person.rb
@@ -328,7 +328,7 @@ class Person < Profile
   end
 
   after_update do |person|
-    person.user.save!
+    person.user.save! unless person.user.changes.blank?
   end
 
   def is_admin?(environment = nil)


=====================================
app/models/profile.rb
=====================================
--- a/app/models/profile.rb
+++ b/app/models/profile.rb
@@ -692,15 +692,15 @@ private :generate_url, :url_options
   after_create :insert_default_article_set
   def insert_default_article_set
     if template
-      copy_articles_from template
+      self.save! if copy_articles_from template
     else
       default_set_of_articles.each do |article|
         article.profile = self
         article.advertise = false
         article.save!
       end
+      self.save!
     end
-    self.save!
   end
 
   # Override this method in subclasses of Profile to create a default article
@@ -721,10 +721,12 @@ private :generate_url, :url_options
   end
 
   def copy_articles_from other
+    return false if other.top_level_articles.empty?
     other.top_level_articles.each do |a|
       copy_article_tree a
     end
     self.articles.reload
+    true
   end
 
   def copy_article_tree(article, parent=nil)


=====================================
app/models/user.rb
=====================================
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -445,7 +445,7 @@ class User < ActiveRecord::Base
 
     def deliver_activation_code
       return if person.is_template?
-      UserMailer.activation_code(self).deliver unless self.activation_code.blank?
+      Delayed::Job.enqueue(UserMailer::Job.new(self, :activation_code)) unless self.activation_code.blank?
     end
 
     def delay_activation_check


=====================================
features/signup.feature
=====================================
--- a/features/signup.feature
+++ b/features/signup.feature
@@ -16,6 +16,7 @@ Feature: signup
       | Full name             | José da Silva         |
     And wait for the captcha signup time
     And I press "Create my account"
+    And there are no pending jobs
     Then I should receive an e-mail on josesilva at example.com
     When I go to login page
     And I fill in "Username" with "josesilva"


=====================================
test/functional/search_controller_test.rb
=====================================
--- a/test/functional/search_controller_test.rb
+++ b/test/functional/search_controller_test.rb
@@ -27,6 +27,7 @@ class SearchControllerTest < ActionController::TestCase
     # By pass user validation on person creation
     user = mock()
     user.stubs(:id).returns(1)
+    user.stubs(:changes).returns(nil)
     user.stubs(:valid?).returns(true)
     user.stubs(:email).returns('some at test.com')
     user.stubs(:save!).returns(true)


=====================================
test/integration/signup_test.rb
=====================================
--- a/test/integration/signup_test.rb
+++ b/test/integration/signup_test.rb
@@ -45,7 +45,7 @@ class SignupTest < ActionDispatch::IntegrationTest
     assert_redirected_to controller: 'home', action: 'welcome'
 
     assert_equal count + 1, User.count
-    assert_equal mail_count + 1, ActionMailer::Base.deliveries.count
+    assert_includes Delayed::Job.all.map{|d|d.name}, 'UserMailer::Job'
 
   end
 


=====================================
test/unit/person_test.rb
=====================================
--- a/test/unit/person_test.rb
+++ b/test/unit/person_test.rb
@@ -1937,11 +1937,18 @@ class PersonTest < ActiveSupport::TestCase
 
   should 'a person follows many articles' do
     person = create_user('article_follower').person
-  
+
     1.upto(10).map do |n|
       person.following_articles <<  fast_create(Article, :profile_id => fast_create(Person))
     end
     assert_equal 10, person.following_articles.count
   end
 
+  should 'not save user after an update on person and user is not touched' do
+    user = create_user('testuser')
+    person = user.person
+    person.user.expects(:save!).never
+    person.save!
+  end
+
 end



View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/5d4a0723d1bc83fed7709faecf699b263ae2ea6f...5b115b7a5a0aff158c3622a5879472596c6b61dd
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20160331/23c0a7be/attachment-0001.html>


More information about the Noosfero-dev mailing list