Sha256: 967cea49abe1c9a317dfb8ba4643963524391e4358317b766e06a537dd62426e
Contents?: true
Size: 1.44 KB
Versions: 4
Compression:
Stored size: 1.44 KB
Contents
require 'spec_helper' describe Upsert do describe "can be speeded up with upserting" do describe 'compared to native ActiveRecord' do it "is faster than new/set/save" do assert_faster_than 'find + new/set/save', lotsa_records do |records| records.each do |selector, setter| if pet = Pet.where(selector).first pet.update_attributes(setter) else pet = Pet.new selector.each do |k, v| pet.send "#{k}=", v end setter.each do |k, v| pet.send "#{k}=", v end pet.save! end end end end it "is faster than find_or_create + update_attributes" do assert_faster_than 'find_or_create + update_attributes', lotsa_records do |records| dynamic_method = nil records.each do |selector, setter| Pet.find_or_create_by(selector).update_attributes(setter) end end end it "is faster than create + rescue/find/update" do assert_faster_than 'create + rescue/find/update', lotsa_records do |records| records.each do |selector, setter| begin Pet.create selector.merge(setter), :without_protection => true rescue Pet.find_or_create_by(selector).update_attributes(setter) end end end end end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
upsert-2.9.10-java | spec/speed_spec.rb |
upsert-2.9.10 | spec/speed_spec.rb |
upsert-2.9.9-universal-java-11 | spec/speed_spec.rb |
upsert-2.9.9 | spec/speed_spec.rb |