ree_lib 1.0.56 → 1.0.58
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 +15 -4
- data/lib/ree_lib/packages/ree_dao/package/ree_dao/associations.rb +9 -6
- data/lib/ree_lib/packages/ree_dao/package/ree_dao/functions/load_agg.rb +14 -3
- data/lib/ree_lib/packages/ree_dao/spec/ree_dao/functions/load_agg/load_agg_spec.rb +48 -11
- 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: bdb25650f338b4be087e72a1ef04fff5b9e1bf47d0b22221ead03743c74de398
|
4
|
+
data.tar.gz: 333d7adc841964ddd5b50d690f6c016b096622ba327953ae5a5fa57d50f7bde1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 220bc20b778767ec025b5402e7f0fb5a32c2cd15b37373e26af20d5de11529a75b79c745fc9e062b5e27d0bf2c62e0438806aad79950498badebc5f980562825
|
7
|
+
data.tar.gz: 375223a38b2016acb6d3bf9f45a01b6e286b95b32dcd2ab39fa2f90e4d1758bc12e3409333b9370a1b4c653c0ee6d6e5d1249891d93fbff159e5d8d2ad2dcf66
|
data/Gemfile.lock
CHANGED
@@ -26,8 +26,8 @@ module ReeDao
|
|
26
26
|
load_association(assoc_type, assoc_name, **opts, &block)
|
27
27
|
end
|
28
28
|
|
29
|
-
def handle_field(
|
30
|
-
|
29
|
+
def handle_field(field_proc)
|
30
|
+
field_proc.call
|
31
31
|
end
|
32
32
|
|
33
33
|
contract(
|
@@ -109,13 +109,24 @@ module ReeDao
|
|
109
109
|
**global_opts
|
110
110
|
).instance_exec(assoc_list, &block)
|
111
111
|
else
|
112
|
-
ReeDao::Associations.new(
|
112
|
+
threads = ReeDao::Associations.new(
|
113
113
|
parent.agg_caller,
|
114
114
|
assoc_list,
|
115
115
|
parent.local_vars,
|
116
116
|
autoload_children,
|
117
117
|
**global_opts
|
118
|
-
).instance_exec(assoc_list, &block)
|
118
|
+
).instance_exec(assoc_list, &block)
|
119
|
+
threads[:association_threads].map do |association, assoc_type, assoc_name, opts, block|
|
120
|
+
Thread.new do
|
121
|
+
association.load(assoc_type, assoc_name, **opts, &block)
|
122
|
+
end
|
123
|
+
end.map(&:join)
|
124
|
+
|
125
|
+
threads[:field_threads].map do |association, field_proc|
|
126
|
+
Thread.new do
|
127
|
+
association.handle_field(field_proc)
|
128
|
+
end
|
129
|
+
end.map(&:join)
|
119
130
|
end
|
120
131
|
end
|
121
132
|
|
@@ -97,17 +97,18 @@ module ReeDao
|
|
97
97
|
association = Association.new(self, list, **global_opts)
|
98
98
|
|
99
99
|
if assoc_type == :field
|
100
|
+
field_proc = opts
|
100
101
|
{
|
101
102
|
association_threads: @assoc_threads,
|
102
|
-
field_threads: @field_threads <<
|
103
|
-
association
|
104
|
-
|
103
|
+
field_threads: @field_threads << [
|
104
|
+
association, field_proc
|
105
|
+
]
|
105
106
|
}
|
106
107
|
else
|
107
108
|
{
|
108
|
-
association_threads: @assoc_threads <<
|
109
|
-
association
|
110
|
-
|
109
|
+
association_threads: @assoc_threads << [
|
110
|
+
association, assoc_type, assoc_name, get_assoc_opts(opts), block
|
111
|
+
],
|
111
112
|
field_threads: @field_threads
|
112
113
|
}
|
113
114
|
end
|
@@ -143,6 +144,8 @@ module ReeDao
|
|
143
144
|
def get_assoc_opts(opts)
|
144
145
|
if opts.is_a?(Proc)
|
145
146
|
opts.call
|
147
|
+
elsif opts.is_a?(Sequel::Dataset)
|
148
|
+
{ scope: opts }
|
146
149
|
else
|
147
150
|
{}
|
148
151
|
end
|
@@ -37,7 +37,9 @@ class ReeDao::LoadAgg
|
|
37
37
|
list = scope.is_a?(Sequel::Dataset) ? scope.all : scope
|
38
38
|
|
39
39
|
if opts[:to_dto]
|
40
|
-
list =
|
40
|
+
list = list.map do |item|
|
41
|
+
list = opts[:to_dto].call(item)
|
42
|
+
end
|
41
43
|
end
|
42
44
|
|
43
45
|
load_associations(list, **opts, &block) if block_given?
|
@@ -66,8 +68,17 @@ class ReeDao::LoadAgg
|
|
66
68
|
if ReeDao.load_sync_associations_enabled?
|
67
69
|
associations
|
68
70
|
else
|
69
|
-
associations[:association_threads].map
|
70
|
-
|
71
|
+
associations[:association_threads].map do |association, assoc_type, assoc_name, opts, block|
|
72
|
+
Thread.new do
|
73
|
+
association.load(assoc_type, assoc_name, **opts, &block)
|
74
|
+
end
|
75
|
+
end.map(&:join)
|
76
|
+
|
77
|
+
associations[:field_threads].map do |association, field_proc|
|
78
|
+
Thread.new do
|
79
|
+
association.handle_field(field_proc)
|
80
|
+
end
|
81
|
+
end.map(&:join)
|
71
82
|
end
|
72
83
|
end
|
73
84
|
end
|
@@ -292,6 +292,22 @@ RSpec.describe :load_agg do
|
|
292
292
|
end
|
293
293
|
end
|
294
294
|
|
295
|
+
class ReeDaoLoadAggTest::UsersAggOnlyDataset
|
296
|
+
include ReeDao::AggregateDSL
|
297
|
+
|
298
|
+
aggregate :users_agg_only_dataset do
|
299
|
+
link :users, from: :ree_dao_load_agg_test
|
300
|
+
link :books, from: :ree_dao_load_agg_test
|
301
|
+
link :load_agg, from: :ree_dao
|
302
|
+
end
|
303
|
+
|
304
|
+
def call(ids_or_scope, **opts)
|
305
|
+
load_agg(users, ids_or_scope, **opts) do
|
306
|
+
has_many :books, books.where(title: "1408")
|
307
|
+
end
|
308
|
+
end
|
309
|
+
end
|
310
|
+
|
295
311
|
class ReeDaoLoadAggTest::UsersAggWithoutDao
|
296
312
|
include ReeDao::AggregateDSL
|
297
313
|
|
@@ -316,6 +332,7 @@ RSpec.describe :load_agg do
|
|
316
332
|
let(:users_agg_autoload_reviews_children) { ReeDaoLoadAggTest::UsersAggAutoloadReviewsChildren.new }
|
317
333
|
let(:users_agg_without_dao) { ReeDaoLoadAggTest::UsersAggWithoutDao.new }
|
318
334
|
let(:users_agg_with_dto) { ReeDaoLoadAggTest::UsersAggWithDto.new }
|
335
|
+
let(:users_agg_only_dataset) { ReeDaoLoadAggTest::UsersAggOnlyDataset.new }
|
319
336
|
let(:organizations) { ReeDaoLoadAggTest::Organizations.new }
|
320
337
|
let(:users) { ReeDaoLoadAggTest::Users.new }
|
321
338
|
let(:user_passports) { ReeDaoLoadAggTest::UserPassports.new }
|
@@ -354,21 +371,41 @@ RSpec.describe :load_agg do
|
|
354
371
|
|
355
372
|
res = users_agg_with_dto.call(
|
356
373
|
users.all,
|
357
|
-
to_dto: -> (
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
)
|
365
|
-
end
|
374
|
+
to_dto: -> (user) {
|
375
|
+
ReeDaoLoadAggTest::UserDto.new(
|
376
|
+
id: user.id,
|
377
|
+
name: user.name,
|
378
|
+
organization_id: user.organization_id,
|
379
|
+
full_name: user.name
|
380
|
+
)
|
366
381
|
}
|
367
382
|
)
|
368
383
|
|
369
|
-
|
384
|
+
expect(res.first.class).to eq(ReeDaoLoadAggTest::UserDto)
|
385
|
+
}
|
386
|
+
|
387
|
+
it {
|
388
|
+
organizations.delete_all
|
389
|
+
users.delete_all
|
390
|
+
|
391
|
+
org = ReeDaoLoadAggTest::Organization.new(name: "Test Org")
|
392
|
+
organizations.put(org)
|
393
|
+
|
394
|
+
user = ReeDaoLoadAggTest::User.new(name: "John", age: 33, organization_id: org.id)
|
395
|
+
users.put(user)
|
396
|
+
|
397
|
+
book_1 = ReeDaoLoadAggTest::Book.new(user_id: user.id, title: "1984")
|
398
|
+
book_2 = ReeDaoLoadAggTest::Book.new(user_id: user.id, title: "1408")
|
399
|
+
book_3 = ReeDaoLoadAggTest::Book.new(user_id: user.id, title: "1408")
|
400
|
+
|
401
|
+
books.put(book_1)
|
402
|
+
books.put(book_2)
|
403
|
+
books.put(book_3)
|
404
|
+
|
405
|
+
res = users_agg_only_dataset.call(users.where(name: "John"))
|
370
406
|
|
371
|
-
|
407
|
+
user = res[0]
|
408
|
+
expect(user.books.map(&:title).uniq).to eq(["1408"])
|
372
409
|
}
|
373
410
|
|
374
411
|
it {
|
data/lib/ree_lib/version.rb
CHANGED