bulk_dependency_eraser 4.1.0 → 4.2.1
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f1ee041fa51d9506fdabf317bd2b72fab8be589073d5fa8c8940c6e5654a6bf6
|
4
|
+
data.tar.gz: 8d68033f0554c47a1818ce8e5f96ed047598c6dd3e302151e53589e3475ebdf8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: feae06d17b683a2a19518eca228fa04374265946cf308f45bd95c0e507fcf2a14cb74a79b45a03d03d7d5ad029769f85a68585234cb31c9ca2e45a38be6a80c7
|
7
|
+
data.tar.gz: 928c7bcc857f6ea3bc97165a93d11d7aaf74b15a90c5219e4bfb38137a22d27edf1edcacdc638b3d0bd39d14c91dfd92957663b2e3bb3cb9e473f997817d4080
|
@@ -128,17 +128,17 @@ module BulkDependencyEraser
|
|
128
128
|
def custom_scope_for_query(query)
|
129
129
|
klass = query.klass
|
130
130
|
if opts_c.proc_scopes_per_class_name.key?(klass.name)
|
131
|
-
opts_c.proc_scopes_per_class_name[klass.name].call(query)
|
132
|
-
|
133
|
-
# See if non-class-mapped proc returns a value
|
134
|
-
non_class_name_mapped_query = opts_c.proc_scopes.call(query)
|
135
|
-
if !non_class_name_mapped_query.nil?
|
136
|
-
return non_class_name_mapped_query
|
137
|
-
else
|
138
|
-
# No custom wrapper, return non-effect default
|
139
|
-
return self.class::DEFAULT_KLASS_MAPPED_SCOPE_WRAPPER.call(query)
|
140
|
-
end
|
131
|
+
result = opts_c.proc_scopes_per_class_name[klass.name].call(query)
|
132
|
+
return result unless result.nil?
|
141
133
|
end
|
134
|
+
|
135
|
+
if opts_c.proc_scopes
|
136
|
+
result = opts_c.proc_scopes.call(query)
|
137
|
+
return result unless result.nil?
|
138
|
+
end
|
139
|
+
|
140
|
+
# Could just return query, but don't wnat to break backwards compatiblity
|
141
|
+
return self.class::DEFAULT_KLASS_MAPPED_SCOPE_WRAPPER.call(query)
|
142
142
|
end
|
143
143
|
|
144
144
|
# Create options container
|
@@ -42,13 +42,16 @@ module BulkDependencyEraser
|
|
42
42
|
disable_read_batching: nil,
|
43
43
|
# Applied to all queries. Useful for taking advantage of specific indexes
|
44
44
|
# - not indexed by klass name. Proc would handle the logic for that.
|
45
|
-
# -
|
45
|
+
# - 4th, and lowest, priority of scopes
|
46
46
|
# - accepts rails query as parameter
|
47
47
|
# - return nil if no applicable scope.
|
48
48
|
proc_scopes: self::DEFAULT_SCOPE_WRAPPER,
|
49
49
|
# Applied to all queries. Useful for taking advantage of specific indexes
|
50
|
-
# -
|
50
|
+
# - 3rd highest priority of scopes
|
51
51
|
proc_scopes_per_class_name: {},
|
52
|
+
# Applied to all queries. Useful for taking advantage of specific indexes
|
53
|
+
# - 2nd highest priority of scopes
|
54
|
+
reading_proc_scopes: self::DEFAULT_SCOPE_WRAPPER,
|
52
55
|
# Applied to reading queries
|
53
56
|
# - 1st priority of scopes
|
54
57
|
reading_proc_scopes_per_class_name: {},
|
@@ -146,11 +149,18 @@ module BulkDependencyEraser
|
|
146
149
|
|
147
150
|
def custom_scope_for_query(query)
|
148
151
|
klass = query.klass
|
152
|
+
|
149
153
|
if opts_c.reading_proc_scopes_per_class_name.key?(klass.name)
|
150
|
-
opts_c.reading_proc_scopes_per_class_name[klass.name].call(query)
|
151
|
-
|
152
|
-
|
154
|
+
result = opts_c.reading_proc_scopes_per_class_name[klass.name].call(query)
|
155
|
+
return result unless result.nil?
|
156
|
+
end
|
157
|
+
|
158
|
+
if opts_c.reading_proc_scopes
|
159
|
+
result = opts_c.reading_proc_scopes.call(query)
|
160
|
+
return result unless result.nil?
|
153
161
|
end
|
162
|
+
|
163
|
+
super(query)
|
154
164
|
end
|
155
165
|
|
156
166
|
# @param [ActiveRecord::Relation] query
|
@@ -41,13 +41,16 @@ module BulkDependencyEraser
|
|
41
41
|
disable_delete_batching: nil,
|
42
42
|
# Applied to all queries. Useful for taking advantage of specific indexes
|
43
43
|
# - not indexed by klass name. Proc would handle the logic for that.
|
44
|
-
# -
|
44
|
+
# - 4th, and lowest, priority of scopes
|
45
45
|
# - accepts rails query as parameter
|
46
46
|
# - return nil if no applicable scope.
|
47
47
|
proc_scopes: self::DEFAULT_SCOPE_WRAPPER,
|
48
48
|
# Applied to all queries. Useful for taking advantage of specific indexes
|
49
|
-
# -
|
49
|
+
# - 3rd highest priority of scopes
|
50
50
|
proc_scopes_per_class_name: {},
|
51
|
+
# Applied to all queries. Useful for taking advantage of specific indexes
|
52
|
+
# - 2nd highest priority of scopes
|
53
|
+
deletion_proc_scopes: self::DEFAULT_SCOPE_WRAPPER,
|
51
54
|
# Applied to deletion queries
|
52
55
|
# - 1st priority of scopes
|
53
56
|
deletion_proc_scopes_per_class_name: {},
|
@@ -55,7 +58,7 @@ module BulkDependencyEraser
|
|
55
58
|
|
56
59
|
def initialize class_names_and_ids: {}, additional_identifiers_by_id: {}, opts: {}
|
57
60
|
@class_names_and_ids = class_names_and_ids
|
58
|
-
@additional_identifiers_by_id = additional_identifiers_by_id
|
61
|
+
@additional_identifiers_by_id = additional_identifiers_by_id || {}
|
59
62
|
super(opts:)
|
60
63
|
end
|
61
64
|
|
@@ -70,7 +73,8 @@ module BulkDependencyEraser
|
|
70
73
|
class_names_and_ids.keys.reverse.each do |class_name|
|
71
74
|
current_class_name = class_name
|
72
75
|
additional_identifiers = additional_identifiers_by_id[class_name]
|
73
|
-
|
76
|
+
# We have to give implementers the ability to make changes to these lists. Even a full clear.
|
77
|
+
# raise "invalid state! #{class_name} not found in 'additional_identifiers_by_id' list" if additional_identifiers.nil?
|
74
78
|
|
75
79
|
# Last in, First out
|
76
80
|
ids = class_names_and_ids[class_name].reverse
|
@@ -103,11 +107,18 @@ module BulkDependencyEraser
|
|
103
107
|
|
104
108
|
def custom_scope_for_query(query)
|
105
109
|
klass = query.klass
|
110
|
+
|
106
111
|
if opts_c.deletion_proc_scopes_per_class_name.key?(klass.name)
|
107
|
-
opts_c.deletion_proc_scopes_per_class_name[klass.name].call(query)
|
108
|
-
|
109
|
-
|
112
|
+
result = opts_c.deletion_proc_scopes_per_class_name[klass.name].call(query)
|
113
|
+
return result unless result.nil?
|
114
|
+
end
|
115
|
+
|
116
|
+
if opts_c.deletion_proc_scopes
|
117
|
+
result = opts_c.deletion_proc_scopes.call(query)
|
118
|
+
return result unless result.nil?
|
110
119
|
end
|
120
|
+
|
121
|
+
return super(query)
|
111
122
|
end
|
112
123
|
|
113
124
|
def batch_size
|
@@ -118,6 +129,7 @@ module BulkDependencyEraser
|
|
118
129
|
opts_c.disable_delete_batching.nil? ? opts_c.disable_batching : opts_c.disable_delete_batching
|
119
130
|
end
|
120
131
|
|
132
|
+
# @param additional_identifiers [Hash] can be nil, if chosen to be so by implementers
|
121
133
|
def delete_by_klass_and_ids(klass, ids, additional_identifiers:)
|
122
134
|
puts "Deleting #{klass.name}'s IDs: #{ids}" if opts_c.verbose
|
123
135
|
query = klass.unscoped
|
@@ -126,7 +138,7 @@ module BulkDependencyEraser
|
|
126
138
|
if batching_disabled?
|
127
139
|
puts "Deleting without batching" if opts_c.verbose
|
128
140
|
# Get column-names/keys of any additional identifer columns
|
129
|
-
detected_additional_identifier_columns = additional_identifiers
|
141
|
+
detected_additional_identifier_columns = additional_identifiers&.values&.flat_map(&:keys)&.uniq || []
|
130
142
|
delete_in_db do
|
131
143
|
deletion_query = query.where(id: ids)
|
132
144
|
# Apply any additional query identifiers (i.e. :ctid column)
|
@@ -144,9 +156,9 @@ module BulkDependencyEraser
|
|
144
156
|
else
|
145
157
|
puts "Deleting with batching" if opts_c.verbose
|
146
158
|
ids.each_slice(batch_size) do |ids_subset|
|
147
|
-
additional_identifiers_subset = additional_identifiers
|
159
|
+
additional_identifiers_subset = additional_identifiers&.slice(*ids_subset)
|
148
160
|
# Get column-names/keys of any additional identifer columns
|
149
|
-
detected_additional_identifier_columns = additional_identifiers_subset
|
161
|
+
detected_additional_identifier_columns = additional_identifiers_subset&.values&.flat_map(&:keys)&.uniq || []
|
150
162
|
delete_in_db do
|
151
163
|
deletion_query = query.where(id: ids_subset)
|
152
164
|
# Apply any additional query identifiers (i.e. :ctid column)
|
@@ -43,13 +43,16 @@ module BulkDependencyEraser
|
|
43
43
|
disable_nullify_batching: nil,
|
44
44
|
# Applied to all queries. Useful for taking advantage of specific indexes
|
45
45
|
# - not indexed by klass name. Proc would handle the logic for that.
|
46
|
-
# -
|
46
|
+
# - 4th, and lowest, priority of scopes
|
47
47
|
# - accepts rails query as parameter
|
48
48
|
# - return nil if no applicable scope.
|
49
49
|
proc_scopes: self::DEFAULT_SCOPE_WRAPPER,
|
50
50
|
# Applied to all queries. Useful for taking advantage of specific indexes
|
51
|
-
# -
|
51
|
+
# - 3rd highest priority of scopes
|
52
52
|
proc_scopes_per_class_name: {},
|
53
|
+
# Applied to all queries. Useful for taking advantage of specific indexes
|
54
|
+
# - 2nd highest priority of scopes
|
55
|
+
nullification_proc_scopes: self::DEFAULT_SCOPE_WRAPPER,
|
53
56
|
# Applied to nullification queries
|
54
57
|
# - 1st priority of scopes
|
55
58
|
nullification_proc_scopes_per_class_name: {},
|
@@ -164,11 +167,18 @@ module BulkDependencyEraser
|
|
164
167
|
|
165
168
|
def custom_scope_for_query(query)
|
166
169
|
klass = query.klass
|
170
|
+
|
167
171
|
if opts_c.nullification_proc_scopes_per_class_name.key?(klass.name)
|
168
|
-
opts_c.nullification_proc_scopes_per_class_name[klass.name].call(query)
|
169
|
-
|
170
|
-
|
172
|
+
result = opts_c.nullification_proc_scopes_per_class_name[klass.name].call(query)
|
173
|
+
return result unless result.nil?
|
174
|
+
end
|
175
|
+
|
176
|
+
if opts_c.nullification_proc_scopes
|
177
|
+
result = opts_c.nullification_proc_scopes.call(query)
|
178
|
+
return result unless result.nil?
|
171
179
|
end
|
180
|
+
|
181
|
+
return super(query)
|
172
182
|
end
|
173
183
|
|
174
184
|
def batch_size
|