I got 2 Models, Main Model and Details Model.
In my Home Controller i want to insert 1.000.000 entries into the database, just for testing issues.
But this is very slow, the inserts are happening very slow.. is it possible to speed this up?
Maybe i did something wrong with the configuration?
Because i want, every time a Main entry is saved, a corresponding detail entry should be created.
Main Model looks like:
class Main < ActiveRecord::Base
has_one :detail, :dependent => :destroy
before_create :build_a_detail
private
def build_a_detail
self.build_detail(:Bezeichnung => 'test', :Koordinaten => 10, :main_id => self.id)
end
end
Detail Model looks like:
class Detail < ActiveRecord::Base
belongs_to :main
end
Home Controller:
def new
for i in 0..1000000
main = Main.new(:Category => 'Krankenhaus', :Latitude => 5, :Longitude => 6)
main.save
end
end
The problem is that a single insert query is executed into the DB for every create and that slows the application.
You can have bulk inserts with Rails too:
Bulk insert in RAILS