Commit 3c0d99a538084bf047ebfe678a47250a56535596

Authored by Daniela Feitosa
2 parents f4910cba b41cf2b2

Merge commit 'refs/merge-requests/145' of git://gitorious.org/noosfero/noosfero …

…into merge-requests/145
app/models/enterprise.rb
@@ -76,7 +76,11 @@ class Enterprise < Organization @@ -76,7 +76,11 @@ class Enterprise < Organization
76 end 76 end
77 77
78 after_save do |e| 78 after_save do |e|
79 - e.products.each{ |p| p.enterprise_updated(e) } 79 + e.delay.update_products_position
  80 + end
  81 +
  82 + def update_products_position
  83 + products.each{ |p| p.enterprise_updated(self) }
80 end 84 end
81 85
82 def closed? 86 def closed?
test/integration/performance_test.rb
@@ -53,6 +53,26 @@ class PerformanceTest < ActionController::IntegrationTest @@ -53,6 +53,26 @@ class PerformanceTest < ActionController::IntegrationTest
53 assert a1 > a2*FACTOR, "#{a1} should be larger than #{a2} by at least a factor of #{FACTOR}" 53 assert a1 > a2*FACTOR, "#{a1} should be larger than #{a2} by at least a factor of #{FACTOR}"
54 end 54 end
55 55
  56 + should 'not have a linear increase in time to save enterprise due to amount of products' do
  57 + enterprise0 = Enterprise.create!(:name => 'Enterprise 0', :identifier => 'enterprise0')
  58 + enterprise1 = Enterprise.create!(:name => 'Enterprise 1', :identifier => 'enterprise1')
  59 + enterprise2 = Enterprise.create!(:name => 'Enterprise 2', :identifier => 'enterprise2')
  60 +
  61 + create_products(enterprise1,25)
  62 + create_products(enterprise2,50)
  63 +
  64 + enterprise0.reload
  65 + enterprise1.reload
  66 + enterprise2.reload
  67 +
  68 + time0 = (Benchmark.measure { 10.times { enterprise0.save! } }).total
  69 + time1 = (Benchmark.measure { 10.times { enterprise1.save! } }).total
  70 + time2 = (Benchmark.measure { 10.times { enterprise2.save! } }).total
  71 +
  72 + assert (time1 - time0) < time0*0.5
  73 + assert (time2 - time0) < time0*0.5
  74 + end
  75 +
56 protected 76 protected
57 77
58 def create_profile(name) 78 def create_profile(name)
@@ -70,5 +90,13 @@ class PerformanceTest &lt; ActionController::IntegrationTest @@ -70,5 +90,13 @@ class PerformanceTest &lt; ActionController::IntegrationTest
70 end 90 end
71 end 91 end
72 92
  93 + def create_products(enterprise,n)
  94 + number = Product.all.count
  95 + pc = ProductCategory.create!(:name => "Any Category #{n}", :environment => Environment.default)
  96 + n.times do |i|
  97 + Product.create!(:enterprise => enterprise, :product_category => pc, :name => "Product #{i+number+1}")
  98 + end
  99 + end
  100 +
73 end 101 end
74 102
test/unit/product_test.rb
@@ -109,7 +109,7 @@ class ProductTest &lt; ActiveSupport::TestCase @@ -109,7 +109,7 @@ class ProductTest &lt; ActiveSupport::TestCase
109 prod = ent.products.create!(:name => 'test product', :product_category => @product_category) 109 prod = ent.products.create!(:name => 'test product', :product_category => @product_category)
110 110
111 ent.lat = 45.0; ent.lng = 45.0; ent.save! 111 ent.lat = 45.0; ent.lng = 45.0; ent.save!
112 - 112 + process_delayed_job_queue
113 prod.reload 113 prod.reload
114 114
115 assert_in_delta 45.0, prod.lat, 0.0001 115 assert_in_delta 45.0, prod.lat, 0.0001