ar-ondemand 1.0.3 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- data/lib/ar-ondemand/delete_all_by_pk.rb +6 -6
- data/lib/ar-ondemand/for_reading.rb +6 -6
- data/lib/ar-ondemand/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MDYxMjI1MWU0YTFkNmI1YzBkYTY1NWI2OTY0OWM4YThiMmZjODhkMw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
M2JkMTFjZmExNWVhZDUyNzc0ODRhNDM5N2VlYjJlMGM2YmJkNzUwZg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
OGJmYTJlZGI1N2UzOTUyYTUzMWNmOGJjYmZkYTMxYTUzNWYwMzM0NzFiNDUw
|
10
|
+
ODBhNzM5ODZmNWNhNWFkNzNiNTc5NzQyNTU3OTk2MmU3NTMyZTkwYzQzNWE1
|
11
|
+
NGRjNzg5Mzc3YTE1NjUwMmE4MWM5MzYzZWNkNjU5OTA0ZjcwYjc=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NzY5NjMwZTA2NDU3ODZhZTY4ODg4MzkxYmJmMzlhZjc0ZTIxYWExYjlhYmFj
|
14
|
+
YzkyZTlmMTJkMDJjMTdlMjE1MTY0NTgwMmQ1OTc4MGNhMDA5YzgzZGM2MjFi
|
15
|
+
MDhmNTE5NDkxZTI5Yzc0MTM5NTJjZGRkOThkOWNjNGNlYTdmM2E=
|
@@ -14,7 +14,7 @@ module ActiveRecord
|
|
14
14
|
end
|
15
15
|
|
16
16
|
if (finder_options = options.except(:start, :batch_size)).present?
|
17
|
-
raise "You can't specify an order, it's forced to be #{
|
17
|
+
raise "You can't specify an order, it's forced to be #{batch_order_delete_all_by_pk}" if options[:order].present?
|
18
18
|
raise "You can't specify a limit, it's forced to be the batch_size" if options[:limit].present?
|
19
19
|
|
20
20
|
relation = apply_finder_options(finder_options)
|
@@ -23,8 +23,8 @@ module ActiveRecord
|
|
23
23
|
start = options.delete(:start)
|
24
24
|
batch_size = options.delete(:batch_size)
|
25
25
|
|
26
|
-
relation = relation.reorder(
|
27
|
-
records = start ?
|
26
|
+
relation = relation.reorder(batch_order_delete_all_by_pk).limit(batch_size) if batch_size
|
27
|
+
records = query_delete_all_by_pk(start ? relation.where(table[primary_key].gteq(start)) : relation)
|
28
28
|
|
29
29
|
while records.any?
|
30
30
|
records_size = records.size
|
@@ -34,18 +34,18 @@ module ActiveRecord
|
|
34
34
|
|
35
35
|
break if batch_size.nil? || records_size < batch_size
|
36
36
|
|
37
|
-
records =
|
37
|
+
records = query_delete_all_by_pk relation.where(table[primary_key].gt(primary_key_offset))
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
41
|
private
|
42
42
|
|
43
|
-
def
|
43
|
+
def query_delete_all_by_pk(ar)
|
44
44
|
results = ::ActiveRecord::Base.connection.exec_query ar.select([table[primary_key]]).to_sql
|
45
45
|
results.rows.flatten
|
46
46
|
end
|
47
47
|
|
48
|
-
def
|
48
|
+
def batch_order_delete_all_by_pk
|
49
49
|
"#{quoted_table_name}.#{quoted_primary_key} ASC"
|
50
50
|
end
|
51
51
|
end
|
@@ -18,7 +18,7 @@ module ActiveRecord
|
|
18
18
|
end
|
19
19
|
|
20
20
|
if (finder_options = options.except(:start, :batch_size)).present?
|
21
|
-
raise "You can't specify an order, it's forced to be #{
|
21
|
+
raise "You can't specify an order, it's forced to be #{batch_order_for_reading}" if options[:order].present?
|
22
22
|
raise "You can't specify a limit, it's forced to be the batch_size" if options[:limit].present?
|
23
23
|
|
24
24
|
relation = apply_finder_options(finder_options)
|
@@ -27,8 +27,8 @@ module ActiveRecord
|
|
27
27
|
start = options.delete(:start)
|
28
28
|
batch_size = options.delete(:batch_size) || 1000
|
29
29
|
|
30
|
-
relation = relation.reorder(
|
31
|
-
records = start ?
|
30
|
+
relation = relation.reorder(batch_order_for_reading).limit(batch_size)
|
31
|
+
records = query_for_reading(start ? relation.where(table[primary_key].gteq(start)) : relation)
|
32
32
|
|
33
33
|
while records.any?
|
34
34
|
records_size = records.size
|
@@ -39,7 +39,7 @@ module ActiveRecord
|
|
39
39
|
break if records_size < batch_size
|
40
40
|
|
41
41
|
if primary_key_offset
|
42
|
-
records =
|
42
|
+
records = query_for_reading relation.where(table[primary_key].gt(primary_key_offset))
|
43
43
|
else
|
44
44
|
raise "Primary key not included in the custom select clause"
|
45
45
|
end
|
@@ -48,12 +48,12 @@ module ActiveRecord
|
|
48
48
|
|
49
49
|
private
|
50
50
|
|
51
|
-
def
|
51
|
+
def query_for_reading(ar)
|
52
52
|
results = ::ActiveRecord::Base.connection.exec_query ar.to_sql
|
53
53
|
::ActiveRecord::OnDemand::ResultSet.new self.arel.engine, results
|
54
54
|
end
|
55
55
|
|
56
|
-
def
|
56
|
+
def batch_order_for_reading
|
57
57
|
"#{quoted_table_name}.#{quoted_primary_key} ASC"
|
58
58
|
end
|
59
59
|
end
|
data/lib/ar-ondemand/version.rb
CHANGED