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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 60f1df6c3a60ce0e7d3048cdcb263986148ca7989464f90859455afea67eae78
4
- data.tar.gz: 5069d8a435cc8ac13a2b4e873318c1c0a4ada041a5ed292b8df58212af3bc887
3
+ metadata.gz: bb8d638145b6ff810e2cb3deb79c11a134b9df5e6abdc25755a166d92158c583
4
+ data.tar.gz: 0f7525a93ddb69db0b0fdb1243973c2a1db1db1d33051fa3fe49e1aaefdb538d
5
5
  SHA512:
6
- metadata.gz: 590c7dc30ca2d04140332d0c97128dcddbfb9a95e07d8a413006faa32011d3343fa5363e1a5a43f3678ae2b96f7ca9e44cdc23775f69a6971d576f000e4254c3
7
- data.tar.gz: 6bff0c448928f611a0c8ce7f684df5b636d66bf0570c793ced8204eb759a1e0ad020e3947caa562610a5410f967b8ee4ef2bdc191aa37abd2e5ec47d497d11c6
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
- # Works in theory for ONE record's has_one, but we're dealing with potentially many
428
- # # Apply limit if has_one assocation (subset of has_many)
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.pluck(specified_foreign_key, specified_foreign_type).each_with_object({}) do |(id, type), hash|
620
- hash.key?(type) ? hash[type] << id : hash[type] = [id]
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
 
@@ -1,3 +1,3 @@
1
1
  module BulkDependencyEraser
2
- VERSION = "1.3.1".freeze
2
+ VERSION = "1.3.3".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bulk_dependency_eraser
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - benjamin.dana.software.dev@gmail.com