ree_lib 1.0.67 → 1.0.69
Sign up to get free protection for your applications and to get access to all the features.
- 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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c746828c8b09f58c0406659649ef01ba7b7300f4b1f35f808f8e1f58a0dc4165
|
4
|
+
data.tar.gz: c03ddd00be42dbbe2ee2e2660a105a84912d19ccb5251fd882bd88d04e5bd781
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5fa6ca950b18d4e6678610f8dd1b1d3c239090e18d7c914be33643e75d846332e041109d8cb2f6d301398e9eafeeb6897320bfac688c2defb427bc2bec6a4e5c
|
7
|
+
data.tar.gz: 13405b30d0b4be4aba5e579f8bab5a410af29fe820a5aca37502ea6a7d356a5d5fdad315214fa70b8581927c7ee712607a101b191ec2d9fd383a4b4e1989f8a8
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
ree_lib (1.0.
|
4
|
+
ree_lib (1.0.69)
|
5
5
|
binding_of_caller (~> 1.0.0)
|
6
6
|
i18n (~> 1.12.0)
|
7
7
|
loofah (~> 2.18.0)
|
@@ -51,7 +51,7 @@ GEM
|
|
51
51
|
rack (>= 1.3)
|
52
52
|
rainbow (3.1.1)
|
53
53
|
rake (13.0.6)
|
54
|
-
ree (1.0.
|
54
|
+
ree (1.0.29)
|
55
55
|
commander (~> 4.6.0)
|
56
56
|
rexml (3.2.5)
|
57
57
|
roda (3.58.0)
|
@@ -147,8 +147,8 @@ RSpec.describe ReeActions::DSL, type: [:autoclean] do
|
|
147
147
|
|
148
148
|
contract Any, Hash => Integer
|
149
149
|
def call(user_access, attrs)
|
150
|
-
user = ReeActionsTest::User.new(name: 'John', age: 30)
|
151
|
-
users_dao.put(user)
|
150
|
+
$user = ReeActionsTest::User.new(name: 'John', age: 30)
|
151
|
+
users_dao.put($user)
|
152
152
|
|
153
153
|
Thread.new do
|
154
154
|
users_dao.put(ReeActionsTest::User.new(name: 'Alex', age: 33))
|
@@ -162,8 +162,7 @@ RSpec.describe ReeActions::DSL, type: [:autoclean] do
|
|
162
162
|
end.join
|
163
163
|
end.join
|
164
164
|
|
165
|
-
$thread_cache = ReeDao::DaoCache.new.
|
166
|
-
.dig(Thread.current.object_id, :users)
|
165
|
+
$thread_cache = ReeDao::DaoCache.new.get(:users, $user.id)
|
167
166
|
|
168
167
|
attrs[:user_id]
|
169
168
|
end
|
@@ -173,7 +172,7 @@ RSpec.describe ReeActions::DSL, type: [:autoclean] do
|
|
173
172
|
Thread.new do
|
174
173
|
ReeActionsTest::TestAction3.new.call('user_access', {user_id: 1})
|
175
174
|
end.join
|
176
|
-
|
177
|
-
expect($thread_cache
|
175
|
+
|
176
|
+
expect($thread_cache).to eq($user.to_h)
|
178
177
|
}
|
179
178
|
end
|
@@ -33,6 +33,13 @@
|
|
33
33
|
|
34
34
|
],
|
35
35
|
"objects": [
|
36
|
+
{
|
37
|
+
"name": "agg",
|
38
|
+
"schema": "packages/ree_dao/schemas/ree_dao/functions/agg.schema.json",
|
39
|
+
"tags": [
|
40
|
+
"fn"
|
41
|
+
]
|
42
|
+
},
|
36
43
|
{
|
37
44
|
"name": "build_connection",
|
38
45
|
"schema": "packages/ree_dao/schemas/ree_dao/functions/build_connection.schema.json",
|
@@ -96,13 +103,6 @@
|
|
96
103
|
"fn"
|
97
104
|
]
|
98
105
|
},
|
99
|
-
{
|
100
|
-
"name": "load_agg",
|
101
|
-
"schema": "packages/ree_dao/schemas/ree_dao/functions/load_agg.schema.json",
|
102
|
-
"tags": [
|
103
|
-
"fn"
|
104
|
-
]
|
105
|
-
},
|
106
106
|
{
|
107
107
|
"name": "one_to_many",
|
108
108
|
"schema": "packages/ree_dao/schemas/ree_dao/functions/one_to_many.schema.json",
|
@@ -1,18 +1,19 @@
|
|
1
1
|
module ReeDao
|
2
2
|
class Association
|
3
3
|
include Ree::LinkDSL
|
4
|
+
include ReeDao::AssociationMethods
|
4
5
|
|
5
6
|
link :demodulize, from: :ree_string
|
6
7
|
link :group_by, from: :ree_array
|
7
8
|
link :index_by, from: :ree_array
|
8
9
|
link :underscore, from: :ree_string
|
9
10
|
|
10
|
-
attr_reader :parent, :
|
11
|
+
attr_reader :parent, :parent_dao, :list, :global_opts
|
11
12
|
|
12
|
-
contract(ReeDao::Associations,
|
13
|
-
def initialize(parent,
|
13
|
+
contract(ReeDao::Associations, Sequel::Dataset, Array, Ksplat[RestKeys => Any] => Any)
|
14
|
+
def initialize(parent, parent_dao, list, **global_opts)
|
14
15
|
@parent = parent
|
15
|
-
@
|
16
|
+
@parent_dao = parent_dao
|
16
17
|
@list = list
|
17
18
|
@global_opts = global_opts
|
18
19
|
end
|
@@ -35,7 +36,7 @@ module ReeDao
|
|
35
36
|
Or[:belongs_to, :has_one, :has_many],
|
36
37
|
Symbol,
|
37
38
|
Ksplat[RestKeys => Any],
|
38
|
-
Optblock =>
|
39
|
+
Optblock => Array
|
39
40
|
)
|
40
41
|
def load_association(assoc_type, assoc_name, **__opts, &block)
|
41
42
|
__opts[:autoload_children] ||= false
|
@@ -46,21 +47,17 @@ module ReeDao
|
|
46
47
|
**__opts
|
47
48
|
)
|
48
49
|
|
49
|
-
|
50
|
-
|
51
|
-
dao_name = if dao
|
52
|
-
dao.first_source_table
|
53
|
-
elsif __opts[:scope].is_a?(Array)
|
54
|
-
name = underscore(demodulize(__opts[:scope].first.class.name))
|
50
|
+
scope = __opts[:scope]
|
55
51
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
52
|
+
dao = if scope.is_a?(Array)
|
53
|
+
return [] if scope.empty?
|
54
|
+
name = underscore(demodulize(scope.first.class.name))
|
55
|
+
find_dao(name, parent, nil)
|
56
|
+
else
|
57
|
+
find_dao(assoc_name, parent, scope)
|
61
58
|
end
|
62
59
|
|
63
|
-
process_block(assoc_index, __opts[:autoload_children], __opts[:to_dto],
|
60
|
+
process_block(assoc_index, __opts[:autoload_children], __opts[:to_dto], dao, &block) if block_given?
|
64
61
|
|
65
62
|
list
|
66
63
|
end
|
@@ -74,7 +71,7 @@ module ReeDao
|
|
74
71
|
case type
|
75
72
|
when :belongs_to
|
76
73
|
one_to_one(
|
77
|
-
|
74
|
+
parent_dao,
|
78
75
|
assoc_name,
|
79
76
|
list,
|
80
77
|
scope: __opts[:scope],
|
@@ -85,7 +82,7 @@ module ReeDao
|
|
85
82
|
)
|
86
83
|
when :has_one
|
87
84
|
one_to_one(
|
88
|
-
|
85
|
+
parent_dao,
|
89
86
|
assoc_name,
|
90
87
|
list,
|
91
88
|
scope: __opts[:scope],
|
@@ -97,7 +94,7 @@ module ReeDao
|
|
97
94
|
)
|
98
95
|
when :has_many
|
99
96
|
one_to_many(
|
100
|
-
|
97
|
+
parent_dao,
|
101
98
|
assoc_name,
|
102
99
|
list,
|
103
100
|
scope: __opts[:scope],
|
@@ -109,8 +106,8 @@ module ReeDao
|
|
109
106
|
end
|
110
107
|
end
|
111
108
|
|
112
|
-
contract(Or[Hash, Array], Bool, Nilor[Proc],
|
113
|
-
def process_block(assoc, autoload_children, to_dto,
|
109
|
+
contract(Or[Hash, Array], Bool, Nilor[Proc], Sequel::Dataset, Block => Any)
|
110
|
+
def process_block(assoc, autoload_children, to_dto, parent_dao, &block)
|
114
111
|
assoc_list = assoc.is_a?(Array) ? assoc : assoc.values.flatten
|
115
112
|
|
116
113
|
if to_dto
|
@@ -119,24 +116,20 @@ module ReeDao
|
|
119
116
|
end
|
120
117
|
end
|
121
118
|
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
119
|
+
associations = ReeDao::Associations.new(
|
120
|
+
parent.agg_caller,
|
121
|
+
assoc_list,
|
122
|
+
parent.local_vars,
|
123
|
+
parent_dao,
|
124
|
+
autoload_children,
|
125
|
+
**global_opts
|
126
|
+
)
|
127
|
+
|
128
|
+
if parent_dao.db.in_transaction? || ReeDao::Associations.sync_mode?
|
129
|
+
associations.instance_exec(assoc_list, &block)
|
131
130
|
else
|
132
|
-
threads =
|
133
|
-
|
134
|
-
assoc_list,
|
135
|
-
parent.local_vars,
|
136
|
-
parent_dao_name,
|
137
|
-
autoload_children,
|
138
|
-
**global_opts
|
139
|
-
).instance_exec(assoc_list, &block)
|
131
|
+
threads = associations.instance_exec(assoc_list, &block)
|
132
|
+
|
140
133
|
threads[:association_threads].map do |association, assoc_type, assoc_name, __opts, block|
|
141
134
|
Thread.new do
|
142
135
|
association.load(assoc_type, assoc_name, **__opts, &block)
|
@@ -152,7 +145,7 @@ module ReeDao
|
|
152
145
|
end
|
153
146
|
|
154
147
|
contract(
|
155
|
-
|
148
|
+
Sequel::Dataset,
|
156
149
|
Symbol,
|
157
150
|
Array,
|
158
151
|
Kwargs[
|
@@ -164,7 +157,7 @@ module ReeDao
|
|
164
157
|
reverse: Bool
|
165
158
|
] => Or[Hash, Array]
|
166
159
|
)
|
167
|
-
def one_to_one(
|
160
|
+
def one_to_one(parent_dao, assoc_name, list, scope: nil, primary_key: :id, foreign_key: nil, setter: nil, to_dto: nil, reverse: true)
|
168
161
|
return {} if list.empty?
|
169
162
|
|
170
163
|
primary_key ||= :id
|
@@ -177,7 +170,7 @@ module ReeDao
|
|
177
170
|
if reverse
|
178
171
|
# has_one
|
179
172
|
if !foreign_key
|
180
|
-
foreign_key = "#{
|
173
|
+
foreign_key = "#{parent_dao.first_source_table.to_s.gsub(/s$/,'')}_id".to_sym
|
181
174
|
end
|
182
175
|
|
183
176
|
root_ids = list.map(&:id).uniq
|
@@ -213,7 +206,7 @@ module ReeDao
|
|
213
206
|
end
|
214
207
|
|
215
208
|
contract(
|
216
|
-
|
209
|
+
Sequel::Dataset,
|
217
210
|
Symbol,
|
218
211
|
Array,
|
219
212
|
Kwargs[
|
@@ -224,7 +217,7 @@ module ReeDao
|
|
224
217
|
to_dto: Nilor[Proc]
|
225
218
|
] => Or[Hash, Array]
|
226
219
|
)
|
227
|
-
def one_to_many(
|
220
|
+
def one_to_many(parent_dao, assoc_name, list, primary_key: nil, foreign_key: nil, scope: nil, setter: nil, to_dto: nil)
|
228
221
|
return {} if list.empty?
|
229
222
|
|
230
223
|
primary_key ||= :id
|
@@ -235,7 +228,7 @@ module ReeDao
|
|
235
228
|
assoc_dao = nil
|
236
229
|
assoc_dao = find_dao(assoc_name, parent, scope)
|
237
230
|
|
238
|
-
foreign_key ||= "#{
|
231
|
+
foreign_key ||= "#{parent_dao.first_source_table.to_s.gsub(/s$/, '')}_id".to_sym
|
239
232
|
|
240
233
|
root_ids = list.map(&:"#{primary_key}")
|
241
234
|
|
@@ -345,20 +338,6 @@ module ReeDao
|
|
345
338
|
res.all
|
346
339
|
end
|
347
340
|
|
348
|
-
def find_dao(assoc_name, parent, scope)
|
349
|
-
dao_from_name = parent.instance_variable_get("@#{assoc_name}") || parent.instance_variable_get("@#{assoc_name}s")
|
350
|
-
return dao_from_name if dao_from_name
|
351
|
-
|
352
|
-
raise ArgumentError, "can't find DAO for :#{assoc_name}, provide correct scope or association name" if scope.nil?
|
353
|
-
return nil if scope.is_a?(Array)
|
354
|
-
|
355
|
-
table_name = scope.first_source_table
|
356
|
-
dao_from_scope = parent.instance_variable_get("@#{table_name}")
|
357
|
-
return dao_from_scope if dao_from_scope
|
358
|
-
|
359
|
-
raise ArgumentError, "can't find DAO for :#{assoc_name}, provide correct scope or association name"
|
360
|
-
end
|
361
|
-
|
362
341
|
def method_missing(method, *args, &block)
|
363
342
|
return super if !parent.agg_caller.private_methods(false).include?(method)
|
364
343
|
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module ReeDao
|
2
|
+
module AssociationMethods
|
3
|
+
def self.included(base)
|
4
|
+
base.include(InstanceMethods)
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.extended(base)
|
8
|
+
base.include(Instance)
|
9
|
+
end
|
10
|
+
|
11
|
+
module InstanceMethods
|
12
|
+
SUFFIXES = ["", "s", "es", "dao", "s_dao", "es_dao"].freeze
|
13
|
+
|
14
|
+
def find_dao(assoc_name, parent_caller, scope = nil)
|
15
|
+
SUFFIXES.each do |suffix|
|
16
|
+
dao_from_name = parent_caller.instance_variable_get("@#{assoc_name}#{suffix}")
|
17
|
+
return dao_from_name if dao_from_name
|
18
|
+
end
|
19
|
+
|
20
|
+
if scope.is_a?(Sequel::Dataset)
|
21
|
+
return scope.unfiltered
|
22
|
+
end
|
23
|
+
|
24
|
+
raise ArgumentError, "can't find DAO for :#{assoc_name}, provide correct scope or association name"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -1,24 +1,25 @@
|
|
1
1
|
module ReeDao
|
2
2
|
class Associations
|
3
3
|
include Ree::LinkDSL
|
4
|
+
include ReeDao::AssociationMethods
|
4
5
|
|
5
|
-
attr_reader :agg_caller, :list, :local_vars, :only, :except, :
|
6
|
+
attr_reader :agg_caller, :list, :local_vars, :only, :except, :parent_dao, :autoload_children, :global_opts
|
6
7
|
|
7
|
-
def initialize(agg_caller, list, local_vars,
|
8
|
+
def initialize(agg_caller, list, local_vars, parent_dao, autoload_children = false, **opts)
|
8
9
|
@agg_caller = agg_caller
|
9
10
|
@list = list
|
10
11
|
@local_vars = local_vars
|
11
12
|
@global_opts = opts || {}
|
12
13
|
@only = opts[:only] if opts[:only]
|
13
14
|
@except = opts[:except] if opts[:except]
|
14
|
-
@
|
15
|
+
@parent_dao = parent_dao
|
15
16
|
@autoload_children = autoload_children
|
16
17
|
|
17
18
|
if @only && @except
|
18
19
|
shared_keys = @only.intersection(@except)
|
19
20
|
|
20
21
|
if shared_keys.size > 0
|
21
|
-
raise ArgumentError.new("you can't use both :only and :except for #{shared_keys.map { "\"#{_1}\"" }.join(", ")} keys")
|
22
|
+
raise ArgumentError.new("you can't use both :only and :except for #{shared_keys.map { "\"#{_1}\"" }.join(", ")} keys")
|
22
23
|
end
|
23
24
|
end
|
24
25
|
|
@@ -86,10 +87,10 @@ module ReeDao
|
|
86
87
|
Optblock => Any
|
87
88
|
)
|
88
89
|
def association(assoc_type, assoc_name, __opts, &block)
|
89
|
-
if self.class.sync_mode?
|
90
|
+
if parent_dao.db.in_transaction? || self.class.sync_mode?
|
90
91
|
return if association_is_not_included?(assoc_name) || list.empty?
|
91
92
|
|
92
|
-
association = Association.new(self,
|
93
|
+
association = Association.new(self, parent_dao, list, **global_opts)
|
93
94
|
|
94
95
|
if assoc_type == :field
|
95
96
|
association.handle_field(assoc_name, __opts)
|
@@ -101,7 +102,7 @@ module ReeDao
|
|
101
102
|
return { association_threads: @assoc_threads, field_threads: @field_threads }
|
102
103
|
end
|
103
104
|
|
104
|
-
association = Association.new(self,
|
105
|
+
association = Association.new(self, parent_dao, list, **global_opts)
|
105
106
|
|
106
107
|
if assoc_type == :field
|
107
108
|
field_proc = __opts
|
@@ -38,11 +38,11 @@ class ReeDao::DaoCache
|
|
38
38
|
private
|
39
39
|
|
40
40
|
def get_thread_object_id(thread)
|
41
|
-
thread
|
41
|
+
thread == Thread.main ? thread.object_id : get_parent_thread(thread)
|
42
42
|
end
|
43
43
|
|
44
44
|
def get_parent_thread(thread)
|
45
|
-
return thread.object_id if thread
|
45
|
+
return thread.object_id if thread == Thread.main
|
46
46
|
|
47
47
|
get_parent_thread(thread.parent)
|
48
48
|
end
|
@@ -56,22 +56,26 @@ class ReeDao::DaoCache
|
|
56
56
|
end
|
57
57
|
|
58
58
|
def add_table_name(table_name)
|
59
|
-
|
60
|
-
|
59
|
+
current_thr_obj_id = current_thread_object_id
|
60
|
+
|
61
|
+
if !@threads[current_thr_obj_id]
|
62
|
+
@threads[current_thr_obj_id] ||= {}
|
61
63
|
end
|
62
64
|
|
63
|
-
@threads[
|
65
|
+
@threads[current_thr_obj_id][table_name] ||= {}
|
64
66
|
end
|
65
67
|
|
66
68
|
def add_primary_key(table_name, primary_key)
|
67
|
-
|
68
|
-
|
69
|
+
current_thr_obj_id = current_thread_object_id
|
70
|
+
|
71
|
+
if !@threads[current_thr_obj_id]
|
72
|
+
@threads[current_thr_obj_id] ||= {}
|
69
73
|
end
|
70
74
|
|
71
|
-
if !@threads[
|
72
|
-
@threads[
|
75
|
+
if !@threads[current_thr_obj_id][table_name]
|
76
|
+
@threads[current_thr_obj_id][table_name] ||= {}
|
73
77
|
end
|
74
78
|
|
75
|
-
@threads[
|
79
|
+
@threads[current_thr_obj_id][table_name][primary_key] ||= {}
|
76
80
|
end
|
77
81
|
end
|
@@ -1,18 +1,16 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
class ReeDao::
|
3
|
+
class ReeDao::Agg
|
4
4
|
include Ree::FnDSL
|
5
5
|
|
6
|
-
fn :
|
7
|
-
link :demodulize, from: :ree_string
|
8
|
-
link :underscore, from: :ree_string
|
6
|
+
fn :agg do
|
9
7
|
link "ree_dao/associations", -> { Associations }
|
10
8
|
link "ree_dao/contract/dao_dataset_contract", -> { DaoDatasetContract }
|
11
9
|
link "ree_dao/contract/entity_contract", -> { EntityContract }
|
12
10
|
end
|
13
11
|
|
14
12
|
contract(
|
15
|
-
|
13
|
+
DaoDatasetContract,
|
16
14
|
Or[Sequel::Dataset, ArrayOf[Integer], ArrayOf[EntityContract], Integer],
|
17
15
|
Ksplat[
|
18
16
|
only?: ArrayOf[Symbol],
|
@@ -22,26 +20,16 @@ class ReeDao::LoadAgg
|
|
22
20
|
],
|
23
21
|
Optblock => ArrayOf[Any]
|
24
22
|
)
|
25
|
-
def call(dao
|
23
|
+
def call(dao, ids_or_scope, **opts, &block)
|
26
24
|
scope = if ids_or_scope.is_a?(Array) && ids_or_scope.any? { _1.is_a?(Integer) }
|
27
|
-
raise ArgumentError.new("Dao should be provided") if dao.nil?
|
28
25
|
return [] if ids_or_scope.empty?
|
29
|
-
|
30
26
|
dao.where(id: ids_or_scope)
|
31
27
|
elsif ids_or_scope.is_a?(Integer)
|
32
|
-
raise ArgumentError.new("Dao should be provided") if dao.nil?
|
33
|
-
|
34
28
|
dao.where(id: ids_or_scope)
|
35
29
|
else
|
36
30
|
ids_or_scope
|
37
31
|
end
|
38
32
|
|
39
|
-
if dao
|
40
|
-
dao_name = dao.first_source_table
|
41
|
-
else
|
42
|
-
dao_name = underscore(demodulize(scope.first.class.name)).to_sym
|
43
|
-
end
|
44
|
-
|
45
33
|
list = scope.is_a?(Sequel::Dataset) ? scope.all : scope
|
46
34
|
|
47
35
|
if opts[:to_dto]
|
@@ -50,7 +38,7 @@ class ReeDao::LoadAgg
|
|
50
38
|
end
|
51
39
|
end
|
52
40
|
|
53
|
-
load_associations(
|
41
|
+
load_associations(dao.unfiltered, list, **opts, &block) if block_given?
|
54
42
|
|
55
43
|
if ids_or_scope.is_a?(Array)
|
56
44
|
list.sort_by { ids_or_scope.index(_1.id) }
|
@@ -61,7 +49,7 @@ class ReeDao::LoadAgg
|
|
61
49
|
|
62
50
|
private
|
63
51
|
|
64
|
-
def load_associations(
|
52
|
+
def load_associations(dao, list, **opts, &block)
|
65
53
|
return if list.empty?
|
66
54
|
|
67
55
|
local_vars = block.binding.eval(<<-CODE, __FILE__, __LINE__ + 1)
|
@@ -71,9 +59,9 @@ class ReeDao::LoadAgg
|
|
71
59
|
|
72
60
|
agg_caller = block.binding.eval("self")
|
73
61
|
|
74
|
-
associations = Associations.new(agg_caller, list, local_vars,
|
62
|
+
associations = Associations.new(agg_caller, list, local_vars, dao, **opts).instance_exec(list, &block)
|
75
63
|
|
76
|
-
if ReeDao.load_sync_associations_enabled?
|
64
|
+
if dao.db.in_transaction? || ReeDao.load_sync_associations_enabled?
|
77
65
|
associations
|
78
66
|
else
|
79
67
|
associations[:association_threads].map do |association, assoc_type, assoc_name, opts, block|
|
@@ -18,17 +18,10 @@ module ReeDao
|
|
18
18
|
require_relative "./ree_dao/dsl"
|
19
19
|
require_relative "./ree_dao/thread_parents"
|
20
20
|
require_relative "./ree_dao/aggregate_dsl"
|
21
|
+
require_relative "./ree_dao/association_methods"
|
21
22
|
require_relative "./ree_dao/associations"
|
22
23
|
require_relative "./ree_dao/association"
|
23
24
|
|
24
|
-
def self.init_cache(thread)
|
25
|
-
ReeDao::Cache.init_cache(thread)
|
26
|
-
end
|
27
|
-
|
28
|
-
def self.drop_cache(thread)
|
29
|
-
ReeDao::Cache.delete_cache(thread)
|
30
|
-
end
|
31
|
-
|
32
25
|
def self.load_sync_associations_enabled?
|
33
26
|
ENV.has_key?("REE_DAO_SYNC_ASSOCIATIONS") && ENV["REE_DAO_SYNC_ASSOCIATIONS"] == "true"
|
34
27
|
end
|
data/lib/ree_lib/packages/ree_dao/schemas/ree_dao/functions/{load_agg.schema.json → agg.schema.json}
RENAMED
@@ -1,10 +1,10 @@
|
|
1
1
|
{
|
2
2
|
"schema_type": "object",
|
3
3
|
"schema_version": "1.1",
|
4
|
-
"name": "
|
5
|
-
"path": "packages/ree_dao/package/ree_dao/functions/
|
4
|
+
"name": "agg",
|
5
|
+
"path": "packages/ree_dao/package/ree_dao/functions/agg.rb",
|
6
6
|
"mount_as": "fn",
|
7
|
-
"class": "ReeDao::
|
7
|
+
"class": "ReeDao::Agg",
|
8
8
|
"factory": null,
|
9
9
|
"methods": [
|
10
10
|
{
|
@@ -16,8 +16,8 @@
|
|
16
16
|
"args": [
|
17
17
|
{
|
18
18
|
"arg": "dao",
|
19
|
-
"arg_type": "
|
20
|
-
"type": "
|
19
|
+
"arg_type": "req",
|
20
|
+
"type": "PackageName::DaoName::Dao: \"SELECT * FROM `table`\""
|
21
21
|
},
|
22
22
|
{
|
23
23
|
"arg": "ids_or_scope",
|
@@ -38,21 +38,6 @@
|
|
38
38
|
}
|
39
39
|
],
|
40
40
|
"links": [
|
41
|
-
{
|
42
|
-
"target": "demodulize",
|
43
|
-
"package_name": "ree_string",
|
44
|
-
"as": "demodulize",
|
45
|
-
"imports": [
|
46
41
|
|
47
|
-
]
|
48
|
-
},
|
49
|
-
{
|
50
|
-
"target": "underscore",
|
51
|
-
"package_name": "ree_string",
|
52
|
-
"as": "underscore",
|
53
|
-
"imports": [
|
54
|
-
|
55
|
-
]
|
56
|
-
}
|
57
42
|
]
|
58
43
|
}
|