ree_lib 1.0.61 → 1.0.62
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/Gemfile.lock +1 -1
- data/lib/ree_lib/packages/ree_dao/package/ree_dao/association.rb +22 -12
- data/lib/ree_lib/packages/ree_dao/spec/ree_dao/functions/load_agg/load_agg_benchmark_spec.rb +3 -3
- data/lib/ree_lib/packages/ree_dao/spec/ree_dao/functions/load_agg/load_agg_spec.rb +13 -8
- data/lib/ree_lib/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: e69b23ef012a6748604d4b82d1d81c791902ee23bc6179d231a340e48289a5d7
|
4
|
+
data.tar.gz: 6233c958a32bfdeea0efaf5b5692d0e824a5e04d9d334bf002d519b0789d6cc3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eee96a99fe5217675f4ff9c3db4915571ae444c7af4a33ca763b786b51a07f77f55fe794aa004688ccfd0f6c00f478631ba100181625de5d5f8d503f62b85edb
|
7
|
+
data.tar.gz: 1abc64ad140c4901e52f62b9a74f30e16f9fd4364a5e066f5321597c4246b7c5d7e2a0cba0515396b1a18aacd27d786321b17fa29004ed7336fac22a8ee75b06
|
data/Gemfile.lock
CHANGED
@@ -4,6 +4,7 @@ module ReeDao
|
|
4
4
|
|
5
5
|
link :group_by, from: :ree_array
|
6
6
|
link :index_by, from: :ree_array
|
7
|
+
link :transform_values, from: :ree_hash
|
7
8
|
|
8
9
|
attr_reader :parent, :parent_dao_name, :list, :global_opts
|
9
10
|
|
@@ -141,7 +142,7 @@ module ReeDao
|
|
141
142
|
contract(
|
142
143
|
Symbol,
|
143
144
|
Symbol,
|
144
|
-
Array,
|
145
|
+
Array,
|
145
146
|
Kwargs[
|
146
147
|
primary_key: Nilor[Symbol],
|
147
148
|
foreign_key: Nilor[Symbol],
|
@@ -160,12 +161,12 @@ module ReeDao
|
|
160
161
|
items = scope
|
161
162
|
else
|
162
163
|
assoc_dao = find_dao(assoc_name, parent, scope)
|
163
|
-
|
164
|
+
|
164
165
|
if reverse
|
165
166
|
if !foreign_key
|
166
|
-
foreign_key = "#{parent_assoc_name.to_s.gsub(/
|
167
|
+
foreign_key = "#{parent_assoc_name.to_s.gsub(/s$/,'')}_id".to_sym
|
167
168
|
end
|
168
|
-
|
169
|
+
|
169
170
|
root_ids = list.map(&:id).uniq
|
170
171
|
else
|
171
172
|
if !foreign_key
|
@@ -174,10 +175,10 @@ module ReeDao
|
|
174
175
|
|
175
176
|
root_ids = list.map(&:"#{foreign_key}").compact
|
176
177
|
end
|
177
|
-
|
178
|
+
|
178
179
|
scope ||= assoc_dao
|
179
180
|
scope = scope.where((reverse ? foreign_key : :id) => root_ids)
|
180
|
-
|
181
|
+
|
181
182
|
items = add_scopes(scope, global_opts[assoc_name])
|
182
183
|
end
|
183
184
|
|
@@ -219,14 +220,14 @@ module ReeDao
|
|
219
220
|
else
|
220
221
|
assoc_dao = nil
|
221
222
|
assoc_dao = find_dao(assoc_name, parent, scope)
|
222
|
-
|
223
|
-
foreign_key ||= "#{parent_assoc_name.to_s.gsub(/
|
224
|
-
|
223
|
+
|
224
|
+
foreign_key ||= "#{parent_assoc_name.to_s.gsub(/s$/, '')}_id".to_sym
|
225
|
+
|
225
226
|
root_ids = list.map(&:"#{primary_key}")
|
226
|
-
|
227
|
+
|
227
228
|
scope ||= assoc_dao
|
228
229
|
scope = scope.where(foreign_key => root_ids)
|
229
|
-
|
230
|
+
|
230
231
|
items = add_scopes(scope, global_opts[assoc_name])
|
231
232
|
end
|
232
233
|
|
@@ -270,13 +271,22 @@ module ReeDao
|
|
270
271
|
|
271
272
|
list.each do |item|
|
272
273
|
if setter && setter.is_a?(Proc)
|
273
|
-
|
274
|
+
if to_dto
|
275
|
+
assoc_index = transform_values(association_index) do |key, value|
|
276
|
+
to_dto.call(value)
|
277
|
+
end
|
278
|
+
|
279
|
+
self.instance_exec(item, assoc_index, &assoc_setter)
|
280
|
+
else
|
281
|
+
self.instance_exec(item, association_index, &assoc_setter)
|
282
|
+
end
|
274
283
|
else
|
275
284
|
key = if reverse.nil?
|
276
285
|
primary_key
|
277
286
|
else
|
278
287
|
reverse ? primary_key : "#{assoc_name}_id"
|
279
288
|
end
|
289
|
+
|
280
290
|
value = association_index[item.send(key)]
|
281
291
|
|
282
292
|
if to_dto && !value.nil?
|
data/lib/ree_lib/packages/ree_dao/spec/ree_dao/functions/load_agg/load_agg_benchmark_spec.rb
CHANGED
@@ -129,7 +129,7 @@ RSpec.describe :load_agg do
|
|
129
129
|
end
|
130
130
|
|
131
131
|
def call(ids_or_scope)
|
132
|
-
load_agg(
|
132
|
+
load_agg(users, ids_or_scope) do
|
133
133
|
belongs_to :organization
|
134
134
|
|
135
135
|
has_many :books
|
@@ -141,7 +141,7 @@ RSpec.describe :load_agg do
|
|
141
141
|
has_many :skills
|
142
142
|
has_many :dreams
|
143
143
|
|
144
|
-
has_one :passport, foreign_key: :user_id, scope: user_passports
|
144
|
+
has_one :passport, -> { {foreign_key: :user_id, scope: user_passports} }
|
145
145
|
end
|
146
146
|
end
|
147
147
|
end
|
@@ -251,7 +251,7 @@ RSpec.describe :load_agg do
|
|
251
251
|
|
252
252
|
_users = []
|
253
253
|
st_time = Time.now
|
254
|
-
puts "
|
254
|
+
puts "Seeding #{NUM_OF_USERS} users..."
|
255
255
|
NUM_OF_USERS.times do
|
256
256
|
u = ReeDaoLoadAggTest::User.new(
|
257
257
|
name: Faker::Name.name,
|
@@ -104,7 +104,7 @@ RSpec.describe :load_agg do
|
|
104
104
|
has_many :books do |books_list|
|
105
105
|
has_one :author
|
106
106
|
has_many :chapters
|
107
|
-
|
107
|
+
|
108
108
|
has_many :reviews do |reviews_list|
|
109
109
|
has_one :review_author
|
110
110
|
|
@@ -113,7 +113,7 @@ RSpec.describe :load_agg do
|
|
113
113
|
|
114
114
|
field :book_calculatetable_field, -> { change_book_titles(books_list) }
|
115
115
|
end
|
116
|
-
|
116
|
+
|
117
117
|
has_one :passport, -> { passport_opts }
|
118
118
|
has_one :custom_field, -> { custom_field_opts }
|
119
119
|
|
@@ -166,7 +166,7 @@ RSpec.describe :load_agg do
|
|
166
166
|
|
167
167
|
has_many :books, -> { books_opts } do
|
168
168
|
has_one :author, -> { author_opts }
|
169
|
-
has_many :chapters, -> { chapters_opts }
|
169
|
+
has_many :chapters, -> { chapters_opts }
|
170
170
|
end
|
171
171
|
end
|
172
172
|
end
|
@@ -174,7 +174,12 @@ RSpec.describe :load_agg do
|
|
174
174
|
private
|
175
175
|
|
176
176
|
def books_opts
|
177
|
-
{
|
177
|
+
{
|
178
|
+
to_dto: -> (book) { ReeDaoLoadAggTest::BookDto.new(book) },
|
179
|
+
setter: -> (item, child_index) {
|
180
|
+
item.set_books(child_index[item.id] || [])
|
181
|
+
}
|
182
|
+
}
|
178
183
|
end
|
179
184
|
|
180
185
|
def author_opts
|
@@ -205,7 +210,7 @@ RSpec.describe :load_agg do
|
|
205
210
|
has_many :books, -> { books_opts } do
|
206
211
|
has_one :author
|
207
212
|
has_many :chapters
|
208
|
-
|
213
|
+
|
209
214
|
has_many :reviews do
|
210
215
|
has_one :review_author
|
211
216
|
end
|
@@ -214,7 +219,7 @@ RSpec.describe :load_agg do
|
|
214
219
|
end
|
215
220
|
|
216
221
|
private
|
217
|
-
|
222
|
+
|
218
223
|
def books_opts
|
219
224
|
{ autoload_children: true }
|
220
225
|
end
|
@@ -239,7 +244,7 @@ RSpec.describe :load_agg do
|
|
239
244
|
has_many :books do
|
240
245
|
has_one :author
|
241
246
|
has_many :chapters
|
242
|
-
|
247
|
+
|
243
248
|
has_many :reviews, -> { { autoload_children: true } } do
|
244
249
|
has_one :review_author
|
245
250
|
end
|
@@ -435,7 +440,7 @@ RSpec.describe :load_agg do
|
|
435
440
|
books.put(book_1)
|
436
441
|
books.put(book_2)
|
437
442
|
books.put(book_3)
|
438
|
-
|
443
|
+
|
439
444
|
res = users_agg_only_dataset.call(users.where(name: "John"))
|
440
445
|
|
441
446
|
user = res[0]
|
data/lib/ree_lib/version.rb
CHANGED