ree_lib 1.0.57 → 1.0.59

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: 84ad4225d13e31575c1799fd4c7a4b480a1e7ae6b9709834447a733a3a260367
4
- data.tar.gz: ba98679b88ac6ad2cec30fcd0280c01638220fdd0a7488f8f33c7ead0dd2de7d
3
+ metadata.gz: ae96c3d6f51872601ad8c4a282cc8119e069a49a2942e624a3eed02817bbf450
4
+ data.tar.gz: 962693ff78a273ff60ab20f1e704759038e0402619c84ce2da5735f16cca28ad
5
5
  SHA512:
6
- metadata.gz: ccbda33bb5233fc869f470993a93ec1770471e6fdce354a49455bf15c487731b06384bb776ed762c172e75428d77a071fc4483087cdbd2de8ef780729ccae3ac
7
- data.tar.gz: d24649974cf1ca2f05c0bece050a7aa91450244cc065f972acacef6f7d966ee52f285c458cf9925d76693b14862d9ebfe77d42142dbb1bea24c3277a26b5a887
6
+ metadata.gz: 562c425026b16d0389287831ea2da44c08e79818c4f238e52f8e3ee0bb62bf36bc8e4bbfc75e3dbe658706a0b735c4c3e0e572287048e9a3095055e7183bfa62
7
+ data.tar.gz: 54c6f30b6c62de9a43284fc76fcf432e9b0c70691de5d0aaf074c8b4cdb9b889f816ee8219c2ba4e660684899793db9a1c3cd7f502f5567fbe32d9df105b7a67
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ree_lib (1.0.57)
4
+ ree_lib (1.0.59)
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
 
@@ -231,7 +242,8 @@ module ReeDao
231
242
  assoc,
232
243
  assoc_name,
233
244
  setter: setter,
234
- primary_key: primary_key
245
+ primary_key: primary_key,
246
+ multiple: true
235
247
  )
236
248
 
237
249
  assoc
@@ -244,10 +256,11 @@ module ReeDao
244
256
  Kwargs[
245
257
  primary_key: Nilor[Symbol],
246
258
  reverse: Nilor[Bool],
247
- setter: Nilor[Or[Symbol, Proc]]
259
+ setter: Nilor[Or[Symbol, Proc]],
260
+ multiple: Bool
248
261
  ] => Any
249
262
  )
250
- def populate_association(list, association_index, assoc_name, primary_key: nil, reverse: nil, setter: nil)
263
+ def populate_association(list, association_index, assoc_name, primary_key: nil, reverse: nil, setter: nil, multiple: false)
251
264
  assoc_setter = if setter
252
265
  setter
253
266
  else
@@ -264,7 +277,8 @@ module ReeDao
264
277
  reverse ? primary_key : "#{assoc_name}_id"
265
278
  end
266
279
  value = association_index[item.send(key)]
267
- next if value.nil?
280
+
281
+ value = [] if value.nil? && multiple
268
282
 
269
283
  begin
270
284
  item.send(assoc_setter, value)
@@ -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
@@ -68,8 +68,17 @@ class ReeDao::LoadAgg
68
68
  if ReeDao.load_sync_associations_enabled?
69
69
  associations
70
70
  else
71
- associations[:association_threads].map(&:join)
72
- 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)
73
82
  end
74
83
  end
75
84
  end
@@ -275,7 +275,7 @@ RSpec.describe :load_agg do
275
275
  load_agg(users, ids_or_scope, **opts) do |agg_list|
276
276
  some_id = agg_list.first.id
277
277
  title = "1984"
278
- belongs_to :organization, organizations.by_name("Corp")
278
+ belongs_to :organization
279
279
 
280
280
  has_many :books, -> { books_opts(title) }
281
281
  end
@@ -465,6 +465,49 @@ RSpec.describe :load_agg do
465
465
  expect(res_user.custom_field).to_not eq(nil)
466
466
  }
467
467
 
468
+ it {
469
+ organizations.delete_all
470
+ users.delete_all
471
+ user_passports.delete_all
472
+ books.delete_all
473
+ chapters.delete_all
474
+
475
+ organization = ReeDaoLoadAggTest::Organization.new(name: "Test Org")
476
+ organizations.put(organization)
477
+
478
+ user_1 = ReeDaoLoadAggTest::User.new(name: "John", age: 33, organization_id: organization.id)
479
+ user_2 = ReeDaoLoadAggTest::User.new(name: "Sam", age: 21, organization_id: organization.id)
480
+ users.put(user_1)
481
+ users.put(user_2)
482
+
483
+ book_1 = ReeDaoLoadAggTest::Book.new(user_id: user_1.id, title: "1984")
484
+ book_2 = ReeDaoLoadAggTest::Book.new(user_id: user_1.id, title: "1408")
485
+
486
+ books.put(book_1)
487
+ books.put(book_2)
488
+
489
+ author_1 = ReeDaoLoadAggTest::Author.new(book_id: book_1.id, name: "George Orwell")
490
+ author_2 = ReeDaoLoadAggTest::Author.new(book_id: book_2.id, name: "Stephen King")
491
+ authors.put(author_1)
492
+ authors.put(author_2)
493
+
494
+ res = users_agg.call(
495
+ users.all
496
+ )
497
+
498
+ expect(res[0].books.first.author).to_not eq(nil)
499
+
500
+ authors.delete(author_1)
501
+ authors.delete(author_2)
502
+
503
+ res = users_agg.call(
504
+ users.all
505
+ )
506
+
507
+ expect(res[0].books[0].author).to eq(nil)
508
+ expect(res[0].books[1].author).to eq(nil)
509
+ }
510
+
468
511
  it {
469
512
  organizations.delete_all
470
513
  users.delete_all
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ReeLib
4
- VERSION = "1.0.57"
4
+ VERSION = "1.0.59"
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.57
4
+ version: 1.0.59
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ruslan Gatiyatov