graphiti 1.5.2 → 1.6.0

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: 1c25ef983bb86cc817c3356590667bcfe2065ea195b6004a0803f9ce771c4288
4
- data.tar.gz: 9215c114b5d98645104bb56fb8b554ce7cb9def5ce4902deca3a3680cfec7c83
3
+ metadata.gz: 5804a85dd275e9e5f160f08c4b4f49f151e4fddc1178a90a66f2a28ef88bd647
4
+ data.tar.gz: 1962ef04b5278bb720e971dca2112e20a9bbb493bbc9428f1b3ca57737e3250f
5
5
  SHA512:
6
- metadata.gz: b2cebcf9995f633281f34a511e86ea11eb0bf72423839fbe0f0796ab65ad3e3d67e29880c55987cb2f3e0d8027e19a0b0ea070cd518a29320b3031bca51a5c50
7
- data.tar.gz: 579ed54aa1cc674244431c2e52f1f24e7e832923de473329c7f0286c9be2982185d60357743f248f8ac831414a7151138a0eb85106af05441788a88628ca6839
6
+ metadata.gz: 95c66786278dea821516ebb0b1f47a249e419a681ac0f461006adfe427fe0d81e9591017187611a7f49dcf14479df47d3501e29c97d4b8fbb9f3c2fc988bc615
7
+ data.tar.gz: 8ccab36d491f3930335d2b42fbddcf18b94403ef7825a80edf33020ba618ff688106719ea49c2f0df798263f12b51b5e0959154ebf85a18737d15c507b024c19
data/.standard.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  fix: true
2
2
  parallel: true
3
- ruby_version: 2.4
3
+ ruby_version: 2.7
4
4
 
5
5
  ignore:
6
6
  - 'vendor/**/*'
data/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  graphiti changelog
2
2
 
3
+ # [1.6.0](https://github.com/graphiti-api/graphiti/compare/v1.5.3...v1.6.0) (2024-03-20)
4
+
5
+
6
+ ### Features
7
+
8
+ * add thread pool and concurrency_max_threads configuration option ([#470](https://github.com/graphiti-api/graphiti/issues/470)) ([697d761](https://github.com/graphiti-api/graphiti/commit/697d76172adec24cd7e7522300c8335233fdcc36))
9
+
10
+ ## [1.5.3](https://github.com/graphiti-api/graphiti/compare/v1.5.2...v1.5.3) (2024-03-18)
11
+
12
+
13
+ ### Bug Fixes
14
+
15
+ * leverage ruby-2.7 parameter forwarding ([#431](https://github.com/graphiti-api/graphiti/issues/431)) ([ae09a46](https://github.com/graphiti-api/graphiti/commit/ae09a464b2156742bb093537deac0578a1a3e40e))
16
+ * prevent :id stripping when :id not in path ([#447](https://github.com/graphiti-api/graphiti/issues/447)) ([e1dd811](https://github.com/graphiti-api/graphiti/commit/e1dd811283f6e6fe7a36b925934df0ecbb4d3411))
17
+
3
18
  ## [1.5.2](https://github.com/graphiti-api/graphiti/compare/v1.5.1...v1.5.2) (2024-03-18)
4
19
 
5
20
 
data/graphiti.gemspec CHANGED
@@ -16,7 +16,7 @@ Gem::Specification.new do |spec|
16
16
  spec.bindir = "exe"
17
17
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
18
  spec.require_paths = ["lib"]
19
- spec.required_ruby_version = ">= 2.6"
19
+ spec.required_ruby_version = ">= 2.7"
20
20
 
21
21
  spec.add_dependency "jsonapi-serializable", "~> 0.3.0"
22
22
  spec.add_dependency "jsonapi-renderer", "~> 0.2", ">= 0.2.2"
@@ -8,6 +8,20 @@ module Graphiti
8
8
  # Defaults to false OR if classes are cached (Rails-only)
9
9
  attr_accessor :concurrency
10
10
 
11
+ # This number must be considered in accordance with the database
12
+ # connection pool size configured in `database.yml`. The connection
13
+ # pool should be large enough to accommodate both the foreground
14
+ # threads (ie. web server or job worker threads) and background
15
+ # threads. For each process, Graphiti will create one global
16
+ # executor that uses this many threads to sideload resources
17
+ # asynchronously. Thus, the pool size should be at least
18
+ # `thread_count + concurrency_max_threads + 1`. For example, if your
19
+ # web server has a maximum of 3 threads, and
20
+ # `concurrency_max_threads` is set to 4, then your pool size should
21
+ # be at least 8.
22
+ # @return [Integer] Maximum number of threads to use when fetching sideloads concurrently
23
+ attr_accessor :concurrency_max_threads
24
+
11
25
  attr_accessor :respond_to
12
26
  attr_accessor :context_for_endpoint
13
27
  attr_accessor :links_on_demand
@@ -26,6 +40,7 @@ module Graphiti
26
40
  def initialize
27
41
  @raise_on_missing_sideload = true
28
42
  @concurrency = false
43
+ @concurrency_max_threads = 4
29
44
  @respond_to = [:json, :jsonapi, :xml]
30
45
  @links_on_demand = false
31
46
  @pagination_links_on_demand = false
@@ -76,7 +76,7 @@ module Graphiti
76
76
  path = request_path
77
77
  if [:update, :show, :destroy].include?(context_namespace) && has_id
78
78
  path = request_path.split("/")
79
- path.pop
79
+ path.pop if path.last == has_id.to_s
80
80
  path = path.join("/")
81
81
  end
82
82
  e[:full_path].to_s == path && e[:actions].include?(context_namespace)
@@ -2,6 +2,23 @@ module Graphiti
2
2
  class Scope
3
3
  attr_accessor :object, :unpaginated_object
4
4
  attr_reader :pagination
5
+
6
+ @thread_pool_executor_mutex = Mutex.new
7
+
8
+ def self.thread_pool_executor
9
+ return @thread_pool_executor if @thread_pool_executor
10
+
11
+ concurrency = Graphiti.config.concurrency_max_threads || 4
12
+ @thread_pool_executor_mutex.synchronize do
13
+ @thread_pool_executor ||= Concurrent::ThreadPoolExecutor.new(
14
+ min_threads: 0,
15
+ max_threads: concurrency,
16
+ max_queue: concurrency * 4,
17
+ fallback_policy: :caller_runs
18
+ )
19
+ end
20
+ end
21
+
5
22
  def initialize(object, resource, query, opts = {})
6
23
  @object = object
7
24
  @resource = resource
@@ -49,7 +66,7 @@ module Graphiti
49
66
  @resource.adapter.close if concurrent
50
67
  }
51
68
  if concurrent
52
- promises << Concurrent::Promise.execute(&resolve_sideload)
69
+ promises << Concurrent::Promise.execute(executor: self.class.thread_pool_executor, &resolve_sideload)
53
70
  else
54
71
  resolve_sideload.call
55
72
  end
@@ -71,9 +71,9 @@ module Graphiti
71
71
  end
72
72
 
73
73
  # Allow access to resource methods
74
- def method_missing(id, *args, &blk)
74
+ def method_missing(id, ...)
75
75
  if @resource.respond_to?(id, true)
76
- @resource.send(id, *args, &blk)
76
+ @resource.send(id, ...)
77
77
  else
78
78
  super
79
79
  end
@@ -1,3 +1,3 @@
1
1
  module Graphiti
2
- VERSION = "1.5.2"
2
+ VERSION = "1.6.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphiti
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.2
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lee Richmond
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-03-18 00:00:00.000000000 Z
11
+ date: 2024-03-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jsonapi-serializable
@@ -353,7 +353,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
353
353
  requirements:
354
354
  - - ">="
355
355
  - !ruby/object:Gem::Version
356
- version: '2.6'
356
+ version: '2.7'
357
357
  required_rubygems_version: !ruby/object:Gem::Requirement
358
358
  requirements:
359
359
  - - ">="