bulk_dependency_eraser 1.3.1 → 1.3.3
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 +4 -4
- data/lib/bulk_dependency_eraser/builder.rb +30 -9
- 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: bb8d638145b6ff810e2cb3deb79c11a134b9df5e6abdc25755a166d92158c583
|
4
|
+
data.tar.gz: 0f7525a93ddb69db0b0fdb1243973c2a1db1db1d33051fa3fe49e1aaefdb538d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8841e5385fdd92b2d1c14315d849df28a4d8af00a7d8f151a4e04767fd27a9b1cd1653d269912a23385520cb7eb18f8e4b483ab74c7f9a0a5249048fbb81f20b
|
7
|
+
data.tar.gz: c0701a14385970abc0ac5ec0025215a11c5818d391d2bcbef89c36e47c8f7a7919a6dbded77521efdb60108bdb88266ef21268e743265399d58c9a7c4044f648
|
@@ -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.
|
@@ -424,11 +427,8 @@ module BulkDependencyEraser
|
|
424
427
|
assoc_query = assoc_query.where(specified_foreign_key.to_sym => query_ids)
|
425
428
|
end
|
426
429
|
|
427
|
-
#
|
428
|
-
|
429
|
-
# if opts[:limit]
|
430
|
-
# assoc_query = assoc_query.limit(opts[:limit])
|
431
|
-
# end
|
430
|
+
# remove any ordering or limits imposed on the association queries from the association definitions
|
431
|
+
assoc_query = assoc_query.reorder('').unscope(:limit)
|
432
432
|
|
433
433
|
if type == :delete
|
434
434
|
# Recursively call 'deletion_query_parser' on association query, to delete any if the assoc's dependencies
|
@@ -551,6 +551,9 @@ module BulkDependencyEraser
|
|
551
551
|
specified_primary_key.to_sym => foreign_keys
|
552
552
|
)
|
553
553
|
|
554
|
+
# remove any ordering or limits imposed on the association queries from the association definitions
|
555
|
+
assoc_query = assoc_query.reorder('').unscope(:limit)
|
556
|
+
|
554
557
|
if type == :delete
|
555
558
|
# Recursively call 'deletion_query_parser' on association query, to delete any if the assoc's dependencies
|
556
559
|
deletion_query_parser(assoc_query, parent_class)
|
@@ -569,6 +572,7 @@ module BulkDependencyEraser
|
|
569
572
|
# This method will replicate association_parser, but instantiate and iterate in batches
|
570
573
|
def association_parser_belongs_to_instantiation(parent_class, query, query_ids, association_name, type)
|
571
574
|
# pending
|
575
|
+
raise "Invalid State! Not ready to instantiate!"
|
572
576
|
end
|
573
577
|
|
574
578
|
# In this case, it's like a `belongs_to :polymorphicable, polymorphic: true, dependent: :destroy` use-case
|
@@ -613,11 +617,28 @@ module BulkDependencyEraser
|
|
613
617
|
return
|
614
618
|
end
|
615
619
|
|
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
620
|
foreign_ids_by_type = read_from_db do
|
619
|
-
query.
|
620
|
-
|
621
|
+
if batching_disabled? || !query.where({}).limit_value.nil?
|
622
|
+
# query without batching
|
623
|
+
query.reorder('').pluck(specified_foreign_key, specified_foreign_type).each_with_object({}) do |(id, type), hash|
|
624
|
+
hash.key?(type) ? hash[type] << id : hash[type] = [id]
|
625
|
+
end
|
626
|
+
else
|
627
|
+
columns_and_ids = {}
|
628
|
+
offset = 0
|
629
|
+
loop do
|
630
|
+
counter = 0
|
631
|
+
query.reorder('').offset(offset).limit(batch_size).pluck(specified_foreign_key, specified_foreign_type).each do |id, type|
|
632
|
+
columns_and_ids.key?(type) ? columns_and_ids[type] << id : columns_and_ids[type] = [id]
|
633
|
+
counter += 1
|
634
|
+
end
|
635
|
+
|
636
|
+
break if counter < batch_size
|
637
|
+
|
638
|
+
# Move to the next batch
|
639
|
+
offset += batch_size
|
640
|
+
end
|
641
|
+
columns_and_ids
|
621
642
|
end
|
622
643
|
end
|
623
644
|
|