graphiti-activegraph 0.1.24 → 0.1.25

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: f43302a065e6583232921abe819bcea82bce10d85893b1cc80d132dd169ebbc0
4
- data.tar.gz: 4aa5cd9c5486ac50d4d0f8844433e931ce55998777aa740014e1a9281b797471
3
+ metadata.gz: 91f9eb76f0b56c276cf1ec4fbef4d535e768c85dbee0d503c3bf9e47c492b509
4
+ data.tar.gz: 9ead092210d92a237fed63c396cf302730fffe601d1fcb0a00a1265563cc0c66
5
5
  SHA512:
6
- metadata.gz: 5604a91acd31eeeecbe45bd7defa41fd2b24612be053463dec11e48d61cc81ed52005050ebb077d5ba9172e1bb012e2bf6d8354a1d27385aeb4276f66ce92283
7
- data.tar.gz: 37ed8852db96fd2dc357afce65069c96ddd664b3c3d33628ab50dfa83aa43d82a5336d779d98d5df59a0f968c20ee7667c4593ce691f95724d548bc146805eba
6
+ metadata.gz: 48334374bd34917e110d55156847d8cc3ba389e45dc76bb7d3db1df2ca8cc59cda5a46ff23c79aff298e0700201d743d3ca04d53b0bb4ae843a3db037c13bff9
7
+ data.tar.gz: cb3ee1de2754dcd3ddfcccc84970aaffc21fa8c2c05e6518299c6bd55c7a4f52830462a9a092152eeb93ece42e3476532094d41bf41d57683eb43d34cf9b1f64
data/.gitignore CHANGED
@@ -45,7 +45,7 @@ build-iPhoneSimulator/
45
45
 
46
46
  # for a library or gem, you might want to ignore these files since the code is
47
47
  # intended to run in multiple environments; otherwise, check them in:
48
- # Gemfile.lock
48
+ /Gemfile.lock
49
49
  # .ruby-version
50
50
  # .ruby-gemset
51
51
 
data/CHANGELOG.md CHANGED
@@ -56,6 +56,12 @@ Features:
56
56
 
57
57
  - Added preliminary support for Sideload backed by function instead of model association
58
58
 
59
+ ## 0.1.25 (04-12-2024)
60
+
61
+ Features:
62
+
63
+ - Added support to preload extra_fields for the main resource, replacing N+1 queries with a single query. This does not apply to sideloaded resources.
64
+
59
65
  <!-- ### [version (DD-MM-YYYY)] -->
60
66
  <!-- Breaking changes:-->
61
67
  <!-- Features:-->
@@ -25,6 +25,9 @@ Gem::Specification.new do |spec|
25
25
  spec.add_development_dependency "faraday", "~> 0.15"
26
26
  spec.add_development_dependency "kaminari", "~> 0.17"
27
27
  spec.add_development_dependency "bundler"
28
+ # dependency conflict introduced during runtime
29
+ # jar-dependencies is a default gem in JRuby and also a dependency in neo4j-ruby-driver
30
+ spec.add_development_dependency "jar-dependencies", "~> 0.4.1"
28
31
  spec.add_development_dependency "rake", "~> 10.0"
29
32
  spec.add_development_dependency "graphiti_spec_helpers", "1.0.beta.4"
30
33
  spec.add_development_dependency "standard"
@@ -23,6 +23,10 @@ module Graphiti
23
23
 
24
24
  def guard_nil_id!(params)
25
25
  end
26
+
27
+ def extra_attribute?(name)
28
+ extra_attributes.has_key?(name)
29
+ end
26
30
  end
27
31
 
28
32
  module ResourceInstanceMethods
@@ -30,6 +34,10 @@ module Graphiti
30
34
  self.class.relation_resource?
31
35
  end
32
36
 
37
+ def extra_attribute?(name)
38
+ self.class.extra_attribute?(name)
39
+ end
40
+
33
41
  def sideload_name_arr(query)
34
42
  query.sideloads.keys.map(&:to_sym)
35
43
  end
@@ -1,5 +1,7 @@
1
1
  module Graphiti::ActiveGraph
2
2
  module SideloadResolve
3
+ PRELOAD_METHOD_PREFIX = 'preload_'.freeze
4
+
3
5
  def initialize(object, resource, query, opts = {})
4
6
  @object = object
5
7
  @resource = resource
@@ -15,5 +17,40 @@ module Graphiti::ActiveGraph
15
17
 
16
18
  def resolve_sideloads(parents)
17
19
  end
20
+
21
+ def resolve
22
+ super.tap { |results| preload_extra_fields(results) }
23
+ end
24
+
25
+ private
26
+
27
+ def preload_extra_fields(results)
28
+ requested_extra_fields.each do |extra_field_name|
29
+ next unless preload_extra_field?(extra_field_name)
30
+
31
+ result_map = fetch_preloaded_data(extra_field_name, results)
32
+ assign_preloaded_data(results, extra_field_name, result_map)
33
+ end
34
+ end
35
+
36
+ def requested_extra_fields
37
+ @query.extra_fields[@resource.type] || []
38
+ end
39
+
40
+ def fetch_preloaded_data(extra_field_name, results)
41
+ @resource.model.public_send(default_preload_method(extra_field_name), results.pluck(:id))
42
+ end
43
+
44
+ def assign_preloaded_data(results, extra_field_name, result_map)
45
+ results.each { |r| r.public_send("#{extra_field_name}=", result_map[r.id]) }
46
+ end
47
+
48
+ def preload_extra_field?(extra_field_name)
49
+ @resource.extra_attribute?(extra_field_name) && @resource.model.respond_to?(default_preload_method(extra_field_name))
50
+ end
51
+
52
+ def default_preload_method(extra_field_name)
53
+ "#{PRELOAD_METHOD_PREFIX}#{extra_field_name}"
54
+ end
18
55
  end
19
56
  end
@@ -1,5 +1,5 @@
1
1
  module Graphiti
2
2
  module ActiveGraph
3
- VERSION = '0.1.24'
3
+ VERSION = '0.1.25'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphiti-activegraph
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.24
4
+ version: 0.1.25
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hardik Joshi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-06-18 00:00:00.000000000 Z
11
+ date: 2024-12-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -108,6 +108,20 @@ dependencies:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ requirement: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: 0.4.1
117
+ name: jar-dependencies
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 0.4.1
111
125
  - !ruby/object:Gem::Dependency
112
126
  requirement: !ruby/object:Gem::Requirement
113
127
  requirements: