bulk_dependency_eraser 1.3.1 → 1.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/bulk_dependency_eraser/builder.rb +24 -4
- data/lib/bulk_dependency_eraser/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7e0b2a7c10501166d33e7076cf19b7c241ffd9de2704d94aca6f7c9fecc6e2d4
|
4
|
+
data.tar.gz: 6788ed915a4a6b4f7d7dbe2c8387244b0ff5e758098fe48f47b47127e64d9fb5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab13a12a9e5965890ae2e27cbf0971ba75aec2dbdc463d92c1631ac9cdb6dd98729e22cedb9c05cfb4cd4f897ca774c5204d0c3a61c804f8f7f8961de4e686cb
|
7
|
+
data.tar.gz: 9d0968970dd212e9e07c459134e829c8b1fd17c3c65d2b1e7665f983a68c4655044e3732ce7e2f6d28fb0c0e59606ffde0f343761a4730abb2f6dc74c3ba521d
|
@@ -152,6 +152,9 @@ module BulkDependencyEraser
|
|
152
152
|
attr_reader :ignore_table_name_and_dependencies, :ignore_klass_name_and_dependencies
|
153
153
|
|
154
154
|
def pluck_from_query query, column = :id
|
155
|
+
# ordering shouldn't matter in these queries, and would slow it down
|
156
|
+
# - we're ignoring default_scope ordering, but assoc-defined ordering would still take effect
|
157
|
+
query = query.reorder('')
|
155
158
|
query_ids = []
|
156
159
|
read_from_db do
|
157
160
|
# If the query has a limit, then we don't want to clobber with batching.
|
@@ -613,11 +616,28 @@ module BulkDependencyEraser
|
|
613
616
|
return
|
614
617
|
end
|
615
618
|
|
616
|
-
# Not sure how to limit/offset batch this right now.
|
617
|
-
# - it's a rare use-case, let's just leave this as a TODO:
|
618
619
|
foreign_ids_by_type = read_from_db do
|
619
|
-
query.
|
620
|
-
|
620
|
+
if batching_disabled? || !query.where({}).limit_value.nil?
|
621
|
+
# query without batching
|
622
|
+
query.reorder('').pluck(specified_foreign_key, specified_foreign_type).each_with_object({}) do |(id, type), hash|
|
623
|
+
hash.key?(type) ? hash[type] << id : hash[type] = [id]
|
624
|
+
end
|
625
|
+
else
|
626
|
+
columns_and_ids = {}
|
627
|
+
offset = 0
|
628
|
+
loop do
|
629
|
+
counter = 0
|
630
|
+
query.reorder('').offset(offset).limit(batch_size).pluck(specified_foreign_key, specified_foreign_type).each do |id, type|
|
631
|
+
columns_and_ids.key?(type) ? columns_and_ids[type] << id : columns_and_ids[type] = [id]
|
632
|
+
counter += 1
|
633
|
+
end
|
634
|
+
|
635
|
+
break if counter < batch_size
|
636
|
+
|
637
|
+
# Move to the next batch
|
638
|
+
offset += batch_size
|
639
|
+
end
|
640
|
+
columns_and_ids
|
621
641
|
end
|
622
642
|
end
|
623
643
|
|