ree_lib 1.0.56 → 1.0.58

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: 23c4603ab3ab820869ca4478b42b3d350c5484c8da7b21c99b469449f45764a1
4
- data.tar.gz: 4293f4d083185f09f6098e11698b5f35981a748b00ff84e486389bab19445751
3
+ metadata.gz: bdb25650f338b4be087e72a1ef04fff5b9e1bf47d0b22221ead03743c74de398
4
+ data.tar.gz: 333d7adc841964ddd5b50d690f6c016b096622ba327953ae5a5fa57d50f7bde1
5
5
  SHA512:
6
- metadata.gz: fe885988996c1f0b9aeba40c9f61e119ab4ffc02aa471afe3774b470192fc5601093c1b13673febebad76bf348baa0be61cb2e19a5abf81b1970b518d86ddc9d
7
- data.tar.gz: acbdf84eacfa6c46c6997999af1e0eb5dc03eedc95b95d954927a3907048c9c28d924328041203d02db1bd5c9dc78310c2cc234db826c74e585a8701b7982ed9
6
+ metadata.gz: 220bc20b778767ec025b5402e7f0fb5a32c2cd15b37373e26af20d5de11529a75b79c745fc9e062b5e27d0bf2c62e0438806aad79950498badebc5f980562825
7
+ data.tar.gz: 375223a38b2016acb6d3bf9f45a01b6e286b95b32dcd2ab39fa2f90e4d1758bc12e3409333b9370a1b4c653c0ee6d6e5d1249891d93fbff159e5d8d2ad2dcf66
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ree_lib (1.0.56)
4
+ ree_lib (1.0.58)
5
5
  binding_of_caller (~> 1.0.0)
6
6
  i18n (~> 1.12.0)
7
7
  loofah (~> 2.18.0)
@@ -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(assoc_name, proc)
30
- proc.call
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)[:association_threads].map(&:join)
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 << Thread.new do
103
- association.handle_field(assoc_name, opts)
104
- end
103
+ field_threads: @field_threads << [
104
+ association, field_proc
105
+ ]
105
106
  }
106
107
  else
107
108
  {
108
- association_threads: @assoc_threads << Thread.new do
109
- association.load(assoc_type, assoc_name, **get_assoc_opts(opts), &block)
110
- end,
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 = opts[:to_dto].call(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(&:join)
70
- associations[:field_threads].map(&:join)
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: -> (users) {
358
- users.map do |user|
359
- ReeDaoLoadAggTest::UserDto.new(
360
- id: user.id,
361
- name: user.name,
362
- organization_id: user.organization_id,
363
- full_name: user.name
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
- res_user = res[0]
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
- expect(res_user.class).to eq(ReeDaoLoadAggTest::UserDto)
407
+ user = res[0]
408
+ expect(user.books.map(&:title).uniq).to eq(["1408"])
372
409
  }
373
410
 
374
411
  it {
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ReeLib
4
- VERSION = "1.0.56"
4
+ VERSION = "1.0.58"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ree_lib
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.56
4
+ version: 1.0.58
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ruslan Gatiyatov