neo4j 5.0.9 → 5.0.10

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
  SHA1:
3
- metadata.gz: 08e5617a201f316c50638b7c32b36d9eaa2f9715
4
- data.tar.gz: bef33cd2fe6fe71d2a961901faab8144da2780a8
3
+ metadata.gz: 70f94d10009b5997fd9e16e1c54d3d8aba81e014
4
+ data.tar.gz: 9b6e7e245073f7f297c412c974a2593c9814dad2
5
5
  SHA512:
6
- metadata.gz: 1d649c9ddcf97089ac43a4c2f716ed0b753dd4a223ef47979d61d3ea5ae02f36c4bca6ed493722b4be44f086899a1165e85458e7ca309f5f974865055becfabc
7
- data.tar.gz: 4acfd71a5ea387a1a2e3f5ed712c435fecbf96d33fd598708429bf359552141cae0c565d415773dd1078c1fee8e244f2d6828236a9fff1af3c2d176dbc382aa6
6
+ metadata.gz: 118af5e336d8da2859e2e784df7af9dc7fdf4d1bd4c30cc2e33e7df1a76ad32defae44313d5fc03dfa10884079a5fbc0bd20932df6ae68c122eb2e0a4af4a10e
7
+ data.tar.gz: 28311d4abb96271ee9abdf5a7a3c6df7ec2e36c4c1481ecd21464b71fa784e3822d5d9d7ff4651dcbc6e70d60e05138caf74cb249acac74c935fa05854aec8fe
@@ -54,9 +54,6 @@ module Neo4j::ActiveNode
54
54
 
55
55
  def cache_query_proxy_result
56
56
  @query_proxy.to_a.tap do |result|
57
- result.each do |object|
58
- object.instance_variable_set('@association_proxy', self)
59
- end
60
57
  cache_result(result)
61
58
  end
62
59
  end
@@ -128,10 +125,10 @@ module Neo4j::ActiveNode
128
125
  name = name.to_sym
129
126
  hash = [name, options.values_at(:node, :rel, :labels)].hash
130
127
  association_proxy_cache_fetch(hash) do
131
- if previous_association_proxy = self.instance_variable_get('@association_proxy')
132
- result_by_previous_id = previous_association_proxy_results_by_previous_id(previous_association_proxy, name)
128
+ if result_cache = self.instance_variable_get('@source_query_proxy_result_cache')
129
+ result_by_previous_id = previous_proxy_results_by_previous_id(result_cache, name)
133
130
 
134
- previous_association_proxy.result.inject(nil) do |proxy_to_return, object|
131
+ result_cache.inject(nil) do |proxy_to_return, object|
135
132
  proxy = fresh_association_proxy(name, options, result_by_previous_id[object.neo_id])
136
133
 
137
134
  object.association_proxy_cache[hash] = proxy
@@ -150,9 +147,9 @@ module Neo4j::ActiveNode
150
147
  AssociationProxy.new(association_query_proxy(name, options), cached_result)
151
148
  end
152
149
 
153
- def previous_association_proxy_results_by_previous_id(association_proxy, association_name)
154
- query_proxy = self.class.as(:previous).where(neo_id: association_proxy.result.map(&:neo_id))
155
- query_proxy = self.class.send(:association_query_proxy, association_name, previous_query_proxy: query_proxy, node: :next)
150
+ def previous_proxy_results_by_previous_id(result_cache, association_name)
151
+ query_proxy = self.class.as(:previous).where(neo_id: result_cache.map(&:neo_id))
152
+ query_proxy = self.class.send(:association_query_proxy, association_name, previous_query_proxy: query_proxy, node: :next, optional: true)
156
153
 
157
154
  Hash[*query_proxy.pluck('ID(previous)', 'collect(next)').flatten(1)]
158
155
  end
@@ -345,7 +342,7 @@ module Neo4j::ActiveNode
345
342
 
346
343
  def association_query_proxy(name, options = {})
347
344
  previous_query_proxy = options[:previous_query_proxy] || current_scope
348
- query_proxy = previous_query_proxy || default_association_query_proxy(name)
345
+ query_proxy = previous_query_proxy || default_association_query_proxy
349
346
  Neo4j::ActiveNode::Query::QueryProxy.new(association_target_class(name),
350
347
  associations[name],
351
348
  {session: neo4j_session,
@@ -380,7 +377,7 @@ module Neo4j::ActiveNode
380
377
  target_classes_or_nil
381
378
  end
382
379
 
383
- def default_association_query_proxy(name)
380
+ def default_association_query_proxy
384
381
  Neo4j::ActiveNode::Query::QueryProxy.new("::#{self.name}".constantize,
385
382
  nil,
386
383
  session: neo4j_session,
@@ -2,38 +2,37 @@ module Neo4j
2
2
  module ActiveNode
3
3
  module Query
4
4
  module QueryProxyEagerLoading
5
- def initialize(model, association = nil, options = {})
6
- @associations_spec = []
7
-
8
- super
9
- end
10
-
11
5
  def each(node = true, rel = nil, &block)
12
- if @associations_spec.size > 0
13
- return_object_clause = '[' + @associations_spec.map { |n| "collect(#{n})" }.join(',') + ']'
14
- query_from_association_spec.pluck(identity, return_object_clause).map do |record, eager_data|
15
- eager_data.each_with_index do |eager_records, index|
16
- record.association_proxy(@associations_spec[index]).cache_result(eager_records)
17
- end
18
-
19
- block.call(record)
6
+ return super if with_associations_spec.size.zero?
7
+
8
+ query_from_association_spec.pluck(identity, with_associations_return_clause).map do |record, eager_data|
9
+ eager_data.each_with_index do |eager_records, index|
10
+ record.association_proxy(with_associations_spec[index]).cache_result(eager_records)
20
11
  end
21
- else
22
- super
12
+
13
+ block.call(record)
23
14
  end
24
15
  end
25
16
 
17
+ def with_associations_spec
18
+ @with_associations_spec ||= []
19
+ end
20
+
21
+ def with_associations_return_clause
22
+ '[' + with_associations_spec.map { |n| "collect(#{n})" }.join(',') + ']'
23
+ end
24
+
26
25
  def with_associations(*spec)
27
26
  new_link.tap do |new_query_proxy|
28
- new_spec = new_query_proxy.instance_variable_get('@associations_spec') + spec
29
- new_query_proxy.instance_variable_set('@associations_spec', new_spec)
27
+ new_spec = new_query_proxy.with_associations_spec + spec
28
+ new_query_proxy.with_associations_spec.replace(new_spec)
30
29
  end
31
30
  end
32
31
 
33
32
  private
34
33
 
35
34
  def query_from_association_spec
36
- @associations_spec.inject(query_as(identity).return(identity)) do |query, association_name|
35
+ with_associations_spec.inject(query_as(identity).return(identity)) do |query, association_name|
37
36
  association = model.associations[association_name]
38
37
 
39
38
  query.optional_match("#{identity}#{association.arrow_cypher}#{association_name}")
@@ -10,11 +10,29 @@ module Neo4j
10
10
  # using `your_node.each(true, true)` instead of `your_node.each_with_rel`.
11
11
  # @return [Enumerable] An enumerable containing some combination of nodes and rels.
12
12
  def each(node = true, rel = nil, &block)
13
+ result(node, rel).each(&block)
14
+ end
15
+
16
+ def result(node = true, rel = true)
17
+ @result_cache ||= {}
18
+ return @result_cache[[node, rel]] if @result_cache[[node, rel]]
19
+
13
20
  pluck_vars = []
14
21
  pluck_vars << identity if node
15
22
  pluck_vars << @rel_var if rel
16
23
 
17
- pluck(*pluck_vars).each(&block)
24
+ result = pluck(*pluck_vars)
25
+
26
+ result.each do |object|
27
+ object.instance_variable_set('@source_query_proxy', self)
28
+ object.instance_variable_set('@source_query_proxy_result_cache', result)
29
+ end
30
+
31
+ @result_cache[[node, rel]] ||= result
32
+ end
33
+
34
+ def fetch_result_cache
35
+ @result_cache ||= yield
18
36
  end
19
37
 
20
38
  # When called at the end of a QueryProxy chain, it will return the resultant relationship objects intead of nodes.
@@ -84,7 +84,7 @@ module Neo4j::Shared
84
84
  # These two methods should be removed in 6.0.0
85
85
  def _destroyed_double_check?
86
86
  if _active_record_destroyed_behavior?
87
- true
87
+ false
88
88
  else
89
89
  (!new_record? && !exist?)
90
90
  end
@@ -1,3 +1,3 @@
1
1
  module Neo4j
2
- VERSION = '5.0.9'
2
+ VERSION = '5.0.10'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: neo4j
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.9
4
+ version: 5.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andreas Ronge, Brian Underwood, Chris Grigg
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-29 00:00:00.000000000 Z
11
+ date: 2015-08-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: orm_adapter