Browse Source

Chore/rails update logic (#5942)

* remove activerecord-import - not being used

* don't make an array of 10k when we only need 500

* no reason to run validations if we don't have any
Gregory Ostermayr 5 years ago
parent
commit
a5b04657fa

+ 0 - 1
frameworks/Ruby/rails/Gemfile

@@ -2,7 +2,6 @@ source 'http://rubygems.org'
 
 
 gem 'unicorn', '5.4.1'
 gem 'unicorn', '5.4.1'
 gem 'puma', '3.12.6'
 gem 'puma', '3.12.6'
-gem 'activerecord-import', '0.27.0'
 gem 'activerecord', '5.2.2', :require => 'active_record'
 gem 'activerecord', '5.2.2', :require => 'active_record'
 gem 'rails', '5.2.2'
 gem 'rails', '5.2.2'
 gem 'tzinfo-data', '1.2018.7'
 gem 'tzinfo-data', '1.2018.7'

+ 2 - 3
frameworks/Ruby/rails/app/controllers/hello_world_controller.rb

@@ -37,15 +37,14 @@ class HelloWorldController < ApplicationController
     queries = 1 if queries < 1
     queries = 1 if queries < 1
     queries = 500 if queries > 500
     queries = 500 if queries > 500
 
 
-    numbers = (1..10000).to_a.sample(queries).sort
-    worlds = numbers.map do |id|
+    worlds = queries.times.map{Random.rand(1..10_000)}.map do |id|
       # get a random row from the database, which we know has 10000
       # get a random row from the database, which we know has 10000
       # rows with ids 1 - 10000
       # rows with ids 1 - 10000
       world = World.select(:id, :randomNumber).find(id)
       world = World.select(:id, :randomNumber).find(id)
       begin
       begin
         rn = Random.rand(1..10000)
         rn = Random.rand(1..10000)
       end while rn == world.randomNumber
       end while rn == world.randomNumber
-      world.update_attribute(:randomNumber, rn)
+      world.update_column(:randomNumber, rn)
       world
       world
     end
     end