active_record_bulk_insert 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -3
- data/lib/active_record_bulk_insert.rb +2 -0
- data/spec/sample_record_spec.rb +8 -0
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c5617c164c167fc88a439beabb1e33362f51a7e6
|
4
|
+
data.tar.gz: 35543d200074044baa24c5e131f88ced54cfcf26
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d175599e02ca65ba95dd3dfbbad4138d6d75d5ec8e438033bec8e1ca586dd27c291fee65f5213854c1cc74974eeb924d851f1bdbba02848c19a2a4c9d12f7db6
|
7
|
+
data.tar.gz: 7f6a9e92d3b090747f3a83ad65ad63fc54be37814dde88b0aba3fd15ab5b653be42ce3b7be3e05a10f28b071a72c131ca822f6375076de998a8efb74e434b3c9
|
data/README.md
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
[![Gem Version](https://badge.fury.io/rb/active_record_bulk_insert.svg)](http://badge.fury.io/rb/active_record_bulk_insert)
|
2
|
-
![Build Status](https://api.travis-ci.org/bjhaid/active_record_bulk_insert.png)
|
3
2
|
|
4
3
|
# BULK INSERT
|
5
4
|
|
@@ -36,7 +35,7 @@ User.bulk_insert([user1, user2])
|
|
36
35
|
User.count # => 2
|
37
36
|
```
|
38
37
|
|
39
|
-
### Evoke Active Record Validations (
|
38
|
+
### Evoke Active Record Validations (after_initialize and validation callbacks)
|
40
39
|
|
41
40
|
```ruby
|
42
41
|
class User < ActiveRecord
|
@@ -73,7 +72,7 @@ User.bulk_insert(users, :disable_timestamps => true)
|
|
73
72
|
users = 1000000.times.map do |i|
|
74
73
|
{:username => "foo#{i}", :firstname => "Foo#{i}", :lastname => "Bar#{i}", :age => (30..70).to_a.sample}
|
75
74
|
end
|
76
|
-
User.bulk_insert_in_batches(users, :batch_size => 10000)
|
75
|
+
User.bulk_insert_in_batches(users, :batch_size => 10000, :delay => 1)
|
77
76
|
User.count # => 1000000
|
78
77
|
```
|
79
78
|
|
@@ -1,9 +1,11 @@
|
|
1
1
|
ActiveRecord::Base.class_eval do
|
2
2
|
def self.bulk_insert_in_batches(attrs, options = {})
|
3
3
|
batch_size = options.fetch(:batch_size, 1000)
|
4
|
+
delay = options.fetch(:delay, nil)
|
4
5
|
|
5
6
|
attrs.each_slice(batch_size).map do |sliced_attrs|
|
6
7
|
bulk_insert(sliced_attrs, options)
|
8
|
+
sleep(delay) if delay
|
7
9
|
end.flatten.compact
|
8
10
|
end
|
9
11
|
|
data/spec/sample_record_spec.rb
CHANGED
@@ -111,5 +111,13 @@ describe SampleRecord do
|
|
111
111
|
|
112
112
|
SampleRecord.bulk_insert_in_batches(records, :batch_size => 2)
|
113
113
|
end
|
114
|
+
|
115
|
+
it "allows you to specify a delay" do
|
116
|
+
records = 10.times.map { |i| SampleRecord.new(:age => 4, :name => "Foo#{i}").attributes }
|
117
|
+
|
118
|
+
SampleRecord.stub!(:sleep)
|
119
|
+
SampleRecord.should_receive(:sleep).with(2)
|
120
|
+
SampleRecord.bulk_insert_in_batches(records, :delay => 2)
|
121
|
+
end
|
114
122
|
end
|
115
123
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_record_bulk_insert
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Abejide Ayodele
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-05-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -73,12 +73,12 @@ executables: []
|
|
73
73
|
extensions: []
|
74
74
|
extra_rdoc_files: []
|
75
75
|
files:
|
76
|
-
- README.md
|
77
76
|
- lib/active_record_bulk_insert.rb
|
78
77
|
- spec/sample_record_spec.rb
|
79
78
|
- spec/spec_helper.rb
|
80
79
|
- spec/support/migrations/1_sample_record_migration.rb
|
81
80
|
- spec/support/sample_record.rb
|
81
|
+
- README.md
|
82
82
|
homepage: https://github.com/bjhaid/active_record_bulk_insert
|
83
83
|
licenses:
|
84
84
|
- MIT
|
@@ -89,22 +89,22 @@ require_paths:
|
|
89
89
|
- lib
|
90
90
|
required_ruby_version: !ruby/object:Gem::Requirement
|
91
91
|
requirements:
|
92
|
-
- -
|
92
|
+
- - '>='
|
93
93
|
- !ruby/object:Gem::Version
|
94
94
|
version: '0'
|
95
95
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
96
|
requirements:
|
97
|
-
- -
|
97
|
+
- - '>='
|
98
98
|
- !ruby/object:Gem::Version
|
99
99
|
version: '0'
|
100
100
|
requirements: []
|
101
101
|
rubyforge_project:
|
102
|
-
rubygems_version: 2.
|
102
|
+
rubygems_version: 2.0.14
|
103
103
|
signing_key:
|
104
104
|
specification_version: 4
|
105
105
|
summary: bulk insert records into the DB
|
106
106
|
test_files:
|
107
|
-
- spec/support/sample_record.rb
|
108
|
-
- spec/support/migrations/1_sample_record_migration.rb
|
109
107
|
- spec/sample_record_spec.rb
|
110
108
|
- spec/spec_helper.rb
|
109
|
+
- spec/support/migrations/1_sample_record_migration.rb
|
110
|
+
- spec/support/sample_record.rb
|