jpie 3.7.0 → 3.8.2

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.
@@ -1,7 +1,23 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "concurrent/map"
4
+
3
5
  module JSONAPI
4
6
  module TypeConversion
7
+ # Type names derive only from a class name plus a resolved format, so the
8
+ # serializer re-computes identical strings once per record and per
9
+ # relationship identifier. Cache frozen results keyed by name and format.
10
+ # The railtie clears the cache on code reload.
11
+ @type_name_cache = Concurrent::Map.new
12
+
13
+ def self.reset_cache!
14
+ @type_name_cache.clear
15
+ end
16
+
17
+ def self.type_name_cache
18
+ @type_name_cache
19
+ end
20
+
5
21
  module_function
6
22
 
7
23
  def type_to_class_name(type, namespace: nil)
@@ -19,18 +35,20 @@ module JSONAPI
19
35
 
20
36
  def model_type_name(model_class, format: nil)
21
37
  format ||= JSONAPI.configuration.namespace_type_format
38
+ name = model_class.name
39
+ return format_type_name(name.underscore.pluralize, format) if name.nil?
22
40
 
23
- full_name = model_class.name.underscore.pluralize
24
-
25
- format_type_name(full_name, format)
41
+ cache = TypeConversion.type_name_cache
42
+ cache["m|#{name}|#{format}"] ||= format_type_name(name.underscore.pluralize, format).freeze
26
43
  end
27
44
 
28
45
  def resource_type_name(definition_class, format: nil)
29
46
  format ||= resolve_type_format(definition_class)
47
+ name = definition_class.name
48
+ return format_type_name(name.sub(/Resource$/, "").underscore.pluralize, format) if name.nil?
30
49
 
31
- full_name = definition_class.name.sub(/Resource$/, "").underscore.pluralize
32
-
33
- format_type_name(full_name, format)
50
+ cache = TypeConversion.type_name_cache
51
+ cache["r|#{name}|#{format}"] ||= format_type_name(name.sub(/Resource$/, "").underscore.pluralize, format).freeze
34
52
  end
35
53
 
36
54
  def format_type_name(full_name, format)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JSONAPI
4
- VERSION = "3.7.0"
4
+ VERSION = "3.8.2"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jpie
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.7.0
4
+ version: 3.8.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emil Kampp
@@ -166,6 +166,7 @@ files:
166
166
  - lib/json_api/serialization/concerns/relationships_deserialization.rb
167
167
  - lib/json_api/serialization/concerns/relationships_serialization.rb
168
168
  - lib/json_api/serialization/deserializer.rb
169
+ - lib/json_api/serialization/include_filter_cache.rb
169
170
  - lib/json_api/serialization/include_path_helpers.rb
170
171
  - lib/json_api/serialization/serializer.rb
171
172
  - lib/json_api/support/active_storage_support.rb