ree_lib 1.0.67 → 1.0.69
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 +2 -2
- data/lib/ree_lib/packages/ree_actions/spec/ree_actions/dsl_spec.rb +5 -6
- data/lib/ree_lib/packages/ree_dao/Package.schema.json +7 -7
- data/lib/ree_lib/packages/ree_dao/package/ree_dao/association.rb +38 -59
- data/lib/ree_lib/packages/ree_dao/package/ree_dao/association_methods.rb +28 -0
- data/lib/ree_lib/packages/ree_dao/package/ree_dao/associations.rb +8 -7
- data/lib/ree_lib/packages/ree_dao/package/ree_dao/beans/dao_cache.rb +14 -10
- data/lib/ree_lib/packages/ree_dao/package/ree_dao/functions/{load_agg.rb → agg.rb} +8 -20
- data/lib/ree_lib/packages/ree_dao/package/ree_dao.rb +1 -8
- data/lib/ree_lib/packages/ree_dao/schemas/ree_dao/functions/{load_agg.schema.json → agg.schema.json} +5 -20
- data/lib/ree_lib/packages/ree_dao/spec/ree_dao/functions/load_agg/{load_agg_benchmark_spec.rb → agg_benchmark_spec.rb} +60 -60
- data/lib/ree_lib/packages/ree_dao/spec/ree_dao/functions/load_agg/agg_spec.rb +981 -0
- data/lib/ree_lib/packages/ree_dao/spec/ree_dao/functions/load_agg/{ree_dao_load_agg_test.rb → ree_dao_agg_test.rb} +56 -56
- data/lib/ree_lib/version.rb +1 -1
- metadata +8 -7
- data/lib/ree_lib/packages/ree_dao/spec/ree_dao/functions/load_agg/load_agg_spec.rb +0 -981
@@ -2,9 +2,9 @@
|
|
2
2
|
require 'faker'
|
3
3
|
require 'benchmark'
|
4
4
|
|
5
|
-
RSpec.
|
5
|
+
RSpec.xdescribe :agg do
|
6
|
+
link :agg, from: :ree_dao
|
6
7
|
link :build_pg_connection, from: :ree_dao
|
7
|
-
link :load_agg, from: :ree_dao
|
8
8
|
|
9
9
|
NUM_OF_USERS = 100
|
10
10
|
ASSOC_COUNT = 10
|
@@ -14,7 +14,7 @@ RSpec.describe :load_agg do
|
|
14
14
|
end
|
15
15
|
|
16
16
|
before :all do
|
17
|
-
connection = build_pg_connection(
|
17
|
+
connection = build_pg_connection(ReeDaoAggTest::Db::DB_CONFIG)
|
18
18
|
|
19
19
|
connection.drop_table(:organizations, cascade: true) if connection.table_exists?(:organizations)
|
20
20
|
connection.drop_table(:users, cascade: true) if connection.table_exists?(:users)
|
@@ -108,28 +108,28 @@ RSpec.describe :load_agg do
|
|
108
108
|
connection.disconnect
|
109
109
|
end
|
110
110
|
|
111
|
-
require_relative '
|
111
|
+
require_relative 'ree_dao_agg_test'
|
112
112
|
|
113
|
-
class
|
113
|
+
class ReeDaoAggTest::AggUsersBenchmark
|
114
114
|
include ReeDao::AggregateDSL
|
115
115
|
|
116
|
-
aggregate :
|
117
|
-
link :users, from: :
|
118
|
-
link :
|
119
|
-
link :user_passports, from: :
|
120
|
-
link :books, from: :
|
121
|
-
link :movies, from: :
|
122
|
-
link :videogames, from: :
|
123
|
-
link :hobbies, from: :
|
124
|
-
link :vinyls, from: :
|
125
|
-
link :pets, from: :
|
126
|
-
link :skills, from: :
|
127
|
-
link :dreams, from: :
|
128
|
-
link :
|
116
|
+
aggregate :agg_users_benchmark do
|
117
|
+
link :users, from: :ree_dao_agg_test
|
118
|
+
link :organizations_dao, from: :ree_dao_agg_test
|
119
|
+
link :user_passports, from: :ree_dao_agg_test
|
120
|
+
link :books, from: :ree_dao_agg_test
|
121
|
+
link :movies, from: :ree_dao_agg_test
|
122
|
+
link :videogames, from: :ree_dao_agg_test
|
123
|
+
link :hobbies, from: :ree_dao_agg_test
|
124
|
+
link :vinyls, from: :ree_dao_agg_test
|
125
|
+
link :pets, from: :ree_dao_agg_test
|
126
|
+
link :skills, from: :ree_dao_agg_test
|
127
|
+
link :dreams, from: :ree_dao_agg_test
|
128
|
+
link :agg, from: :ree_dao
|
129
129
|
end
|
130
130
|
|
131
131
|
def call(ids_or_scope)
|
132
|
-
|
132
|
+
agg(users, ids_or_scope) do
|
133
133
|
belongs_to :organization
|
134
134
|
|
135
135
|
has_many :books
|
@@ -146,21 +146,21 @@ RSpec.describe :load_agg do
|
|
146
146
|
end
|
147
147
|
end
|
148
148
|
|
149
|
-
class
|
149
|
+
class ReeDaoAggTest::UsersSyncFetcher
|
150
150
|
include Ree::FnDSL
|
151
151
|
|
152
152
|
fn :users_sync_fetcher do
|
153
|
-
link :users, from: :
|
154
|
-
link :
|
155
|
-
link :user_passports, from: :
|
156
|
-
link :books, from: :
|
157
|
-
link :movies, from: :
|
158
|
-
link :videogames, from: :
|
159
|
-
link :hobbies, from: :
|
160
|
-
link :vinyls, from: :
|
161
|
-
link :pets, from: :
|
162
|
-
link :skills, from: :
|
163
|
-
link :dreams, from: :
|
153
|
+
link :users, from: :ree_dao_agg_test
|
154
|
+
link :organizations_dao, from: :ree_dao_agg_test
|
155
|
+
link :user_passports, from: :ree_dao_agg_test
|
156
|
+
link :books, from: :ree_dao_agg_test
|
157
|
+
link :movies, from: :ree_dao_agg_test
|
158
|
+
link :videogames, from: :ree_dao_agg_test
|
159
|
+
link :hobbies, from: :ree_dao_agg_test
|
160
|
+
link :vinyls, from: :ree_dao_agg_test
|
161
|
+
link :pets, from: :ree_dao_agg_test
|
162
|
+
link :skills, from: :ree_dao_agg_test
|
163
|
+
link :dreams, from: :ree_dao_agg_test
|
164
164
|
link :one_to_many, from: :ree_dao
|
165
165
|
link :one_to_one, from: :ree_dao
|
166
166
|
end
|
@@ -169,7 +169,7 @@ RSpec.describe :load_agg do
|
|
169
169
|
Or[Sequel::Dataset, ArrayOf[Integer]],
|
170
170
|
Kwargs[
|
171
171
|
include: ArrayOf[Symbol]
|
172
|
-
] => ArrayOf[
|
172
|
+
] => ArrayOf[ReeDaoAggTest::User]
|
173
173
|
)
|
174
174
|
def call(ids_or_scope, include: [])
|
175
175
|
scope = if ids_or_scope.is_a?(Array)
|
@@ -183,7 +183,7 @@ RSpec.describe :load_agg do
|
|
183
183
|
return [] if list.empty?
|
184
184
|
|
185
185
|
if include.include?(:organization)
|
186
|
-
one_to_one(list,
|
186
|
+
one_to_one(list, organizations_dao.order(:id))
|
187
187
|
end
|
188
188
|
|
189
189
|
if include.include?(:books)
|
@@ -230,23 +230,23 @@ RSpec.describe :load_agg do
|
|
230
230
|
end
|
231
231
|
end
|
232
232
|
|
233
|
-
let(:
|
234
|
-
let(:users_sync_fetcher) {
|
235
|
-
|
236
|
-
let(:organizations) {
|
237
|
-
let(:users) {
|
238
|
-
let(:user_passports) {
|
239
|
-
let(:books) {
|
240
|
-
let(:movies) {
|
241
|
-
let(:videogames) {
|
242
|
-
let(:hobbies) {
|
243
|
-
let(:vinyls) {
|
244
|
-
let(:pets) {
|
245
|
-
let(:skills) {
|
246
|
-
let(:dreams) {
|
233
|
+
let(:agg_users) { ReeDaoAggTest::AggUsersBenchmark.new }
|
234
|
+
let(:users_sync_fetcher) { ReeDaoAggTest::UsersSyncFetcher.new }
|
235
|
+
|
236
|
+
let(:organizations) { ReeDaoAggTest::OrganizationsDao.new }
|
237
|
+
let(:users) { ReeDaoAggTest::Users.new }
|
238
|
+
let(:user_passports) { ReeDaoAggTest::UserPassports.new }
|
239
|
+
let(:books) { ReeDaoAggTest::Books.new }
|
240
|
+
let(:movies) { ReeDaoAggTest::Movies.new }
|
241
|
+
let(:videogames) { ReeDaoAggTest::Videogames.new }
|
242
|
+
let(:hobbies) { ReeDaoAggTest::Hobbies.new }
|
243
|
+
let(:vinyls) { ReeDaoAggTest::Vinyls.new }
|
244
|
+
let(:pets) { ReeDaoAggTest::Pets.new }
|
245
|
+
let(:skills) { ReeDaoAggTest::Skills.new }
|
246
|
+
let(:dreams) { ReeDaoAggTest::Dreams.new }
|
247
247
|
|
248
248
|
before(:each) do
|
249
|
-
organization =
|
249
|
+
organization = ReeDaoAggTest::Organization.new(name: "Test Org")
|
250
250
|
organizations.put(organization)
|
251
251
|
|
252
252
|
_users = []
|
@@ -255,7 +255,7 @@ RSpec.describe :load_agg do
|
|
255
255
|
puts "Seeding #{NUM_OF_USERS} users..."
|
256
256
|
|
257
257
|
NUM_OF_USERS.times do
|
258
|
-
u =
|
258
|
+
u = ReeDaoAggTest::User.new(
|
259
259
|
name: Faker::Name.name,
|
260
260
|
age: rand(18..50),
|
261
261
|
organization_id: organization.id
|
@@ -268,7 +268,7 @@ RSpec.describe :load_agg do
|
|
268
268
|
_users.each do |user|
|
269
269
|
ASSOC_COUNT.times do
|
270
270
|
books.put(
|
271
|
-
|
271
|
+
ReeDaoAggTest::Book.new(
|
272
272
|
title: Faker::Book.title,
|
273
273
|
user_id: user.id
|
274
274
|
)
|
@@ -277,7 +277,7 @@ RSpec.describe :load_agg do
|
|
277
277
|
|
278
278
|
ASSOC_COUNT.times do
|
279
279
|
movies.put(
|
280
|
-
|
280
|
+
ReeDaoAggTest::Movie.new(
|
281
281
|
user_id: user.id,
|
282
282
|
title: Faker::Movie.title
|
283
283
|
)
|
@@ -286,7 +286,7 @@ RSpec.describe :load_agg do
|
|
286
286
|
|
287
287
|
ASSOC_COUNT.times do
|
288
288
|
videogames.put(
|
289
|
-
|
289
|
+
ReeDaoAggTest::Videogame.new(
|
290
290
|
user_id: user.id,
|
291
291
|
title: Faker::Game.title
|
292
292
|
)
|
@@ -295,7 +295,7 @@ RSpec.describe :load_agg do
|
|
295
295
|
|
296
296
|
ASSOC_COUNT.times do
|
297
297
|
hobbies.put(
|
298
|
-
|
298
|
+
ReeDaoAggTest::Hobby.new(
|
299
299
|
user_id: user.id,
|
300
300
|
title: Faker::Hobby.activity
|
301
301
|
)
|
@@ -304,7 +304,7 @@ RSpec.describe :load_agg do
|
|
304
304
|
|
305
305
|
ASSOC_COUNT.times do
|
306
306
|
vinyls.put(
|
307
|
-
|
307
|
+
ReeDaoAggTest::Vinyl.new(
|
308
308
|
user_id: user.id,
|
309
309
|
title: Faker::Music.band
|
310
310
|
)
|
@@ -313,7 +313,7 @@ RSpec.describe :load_agg do
|
|
313
313
|
|
314
314
|
ASSOC_COUNT.times do
|
315
315
|
pets.put(
|
316
|
-
|
316
|
+
ReeDaoAggTest::Pet.new(
|
317
317
|
user_id: user.id,
|
318
318
|
name: Faker::Creature::Animal.name
|
319
319
|
)
|
@@ -322,7 +322,7 @@ RSpec.describe :load_agg do
|
|
322
322
|
|
323
323
|
ASSOC_COUNT.times do
|
324
324
|
skills.put(
|
325
|
-
|
325
|
+
ReeDaoAggTest::Skill.new(
|
326
326
|
user_id: user.id,
|
327
327
|
title: Faker::Job.key_skill
|
328
328
|
)
|
@@ -331,7 +331,7 @@ RSpec.describe :load_agg do
|
|
331
331
|
|
332
332
|
ASSOC_COUNT.times do
|
333
333
|
dreams.put(
|
334
|
-
|
334
|
+
ReeDaoAggTest::Dream.new(
|
335
335
|
user_id: user.id,
|
336
336
|
description: Faker::ChuckNorris.fact
|
337
337
|
)
|
@@ -340,7 +340,7 @@ RSpec.describe :load_agg do
|
|
340
340
|
|
341
341
|
ASSOC_COUNT.times do
|
342
342
|
user_passports.put(
|
343
|
-
|
343
|
+
ReeDaoAggTest::UserPassport.new(
|
344
344
|
user_id: user.id,
|
345
345
|
info: "Passport info #{user.id}"
|
346
346
|
)
|
@@ -358,12 +358,12 @@ RSpec.describe :load_agg do
|
|
358
358
|
|
359
359
|
benchmark_res = Benchmark.bm do |x|
|
360
360
|
x.report("async_load_agg") do
|
361
|
-
res1 =
|
361
|
+
res1 = agg_users.call(users.all.map(&:id))
|
362
362
|
end
|
363
363
|
|
364
364
|
x.report("sync_load_agg ") do
|
365
365
|
ENV['REE_DAO_SYNC_ASSOCIATIONS'] = "true"
|
366
|
-
res2 =
|
366
|
+
res2 = agg_users.call(users.all.map(&:id))
|
367
367
|
ENV.delete('REE_DAO_SYNC_ASSOCIATIONS')
|
368
368
|
end
|
369
369
|
|