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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 60f1df6c3a60ce0e7d3048cdcb263986148ca7989464f90859455afea67eae78
4
- data.tar.gz: 5069d8a435cc8ac13a2b4e873318c1c0a4ada041a5ed292b8df58212af3bc887
3
+ metadata.gz: 7e0b2a7c10501166d33e7076cf19b7c241ffd9de2704d94aca6f7c9fecc6e2d4
4
+ data.tar.gz: 6788ed915a4a6b4f7d7dbe2c8387244b0ff5e758098fe48f47b47127e64d9fb5
5
5
  SHA512:
6
- metadata.gz: 590c7dc30ca2d04140332d0c97128dcddbfb9a95e07d8a413006faa32011d3343fa5363e1a5a43f3678ae2b96f7ca9e44cdc23775f69a6971d576f000e4254c3
7
- data.tar.gz: 6bff0c448928f611a0c8ce7f684df5b636d66bf0570c793ced8204eb759a1e0ad020e3947caa562610a5410f967b8ee4ef2bdc191aa37abd2e5ec47d497d11c6
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.pluck(specified_foreign_key, specified_foreign_type).each_with_object({}) do |(id, type), hash|
620
- hash.key?(type) ? hash[type] << id : hash[type] = [id]
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
 
@@ -1,3 +1,3 @@
1
1
  module BulkDependencyEraser
2
- VERSION = "1.3.1".freeze
2
+ VERSION = "1.3.2".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.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - benjamin.dana.software.dev@gmail.com