pluck_each 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pluck_each/version.rb +1 -1
- data/lib/pluck_each.rb +27 -18
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e38a2e5de6b397dab4950becd1de9a80b703dd4e
|
4
|
+
data.tar.gz: 0f3798ecff31d3f35ece1f6ecedcea9ce657a233
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4cfd3aff95b389605210a1721da6361de08ef10ed15f70e269be0f846f48811afa7f4791fa559bdc13def4da414a0545e61a64fb2b1b118c144971740d9f753f
|
7
|
+
data.tar.gz: d3009c05a01c391bda8294158abab7fe8d45ad432fefa64304cd99a50f4c0f11d675d68d9c9ad3b050709a4e955eb7fca651bb8f1f6948ff9220d87d0a11178b
|
data/lib/pluck_each/version.rb
CHANGED
data/lib/pluck_each.rb
CHANGED
@@ -14,32 +14,41 @@ module ActiveRecord
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
def pluck_in_batches(*
|
18
|
-
options =
|
17
|
+
def pluck_in_batches(*column_names)
|
18
|
+
options = column_names.extract_options!
|
19
|
+
string_column_names = column_names.map(&:to_s)
|
20
|
+
|
21
|
+
# Ensure the primary key is selected so we can use it as an offset
|
22
|
+
id_in_columns_requested = string_column_names.include?(primary_key)
|
23
|
+
string_column_names.unshift(primary_key) unless id_in_columns_requested
|
24
|
+
id_position_in_response = string_column_names.index(primary_key)
|
25
|
+
|
19
26
|
relation = self
|
20
27
|
batch_size = options[:batch_size] || 1000
|
21
|
-
offset = 0
|
22
28
|
|
23
|
-
relation = relation.reorder(
|
24
|
-
|
29
|
+
relation = relation.reorder(batch_order).limit(batch_size)
|
30
|
+
batch_relation = relation
|
25
31
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
break if records_size <= 0
|
32
|
+
loop do
|
33
|
+
batch = batch_relation.pluck(*string_column_names)
|
34
|
+
break if batch.empty?
|
30
35
|
|
31
|
-
|
36
|
+
primary_key_offset = batch.last.at(id_position_in_response)
|
32
37
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
38
|
+
unless id_in_columns_requested
|
39
|
+
batch.collect! do |record|
|
40
|
+
record.delete_at(id_position_in_response)
|
41
|
+
record
|
42
|
+
end
|
43
|
+
end
|
37
44
|
|
38
|
-
|
45
|
+
batch.flatten! if column_names.size == 1
|
39
46
|
|
40
|
-
|
41
|
-
"#{quoted_table_name}.#{quoted_primary_key} ASC"
|
42
|
-
end
|
47
|
+
yield batch
|
43
48
|
|
49
|
+
break if batch.size < batch_size
|
50
|
+
batch_relation = relation.where(arel_attribute(primary_key).gt(primary_key_offset))
|
51
|
+
end
|
52
|
+
end
|
44
53
|
end
|
45
54
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pluck_each
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brandon Dewitt
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-11-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -146,7 +146,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
146
146
|
version: '0'
|
147
147
|
requirements: []
|
148
148
|
rubyforge_project:
|
149
|
-
rubygems_version: 2.
|
149
|
+
rubygems_version: 2.5.1
|
150
150
|
signing_key:
|
151
151
|
specification_version: 4
|
152
152
|
summary: pluck_each and plucK_in_batches ... should behave like find_each and find_in_batches
|