Performance and memory usage fixes (#2309)

* Use select and reject instead of partition.map

* Sort adapters keys in place

* Just select from options

* Add changelog entry
This commit is contained in:
Krzysztof Rybka 2019-01-29 22:38:11 +01:00 committed by Benjamin Fleischer
parent 22f2cb76dd
commit 209834dc49
4 changed files with 5 additions and 4 deletions

View File

@ -11,6 +11,7 @@ Fixes:
- [#2307](https://github.com/rails-api/active_model_serializers/pull/2307) Falsey attribute values should not be reevaluated.
Misc:
- [#2309](https://github.com/rails-api/active_model_serializers/pull/2309) Performance and memory usage fixes
### [v0.10.8 (2018-11-01)](https://github.com/rails-api/active_model_serializers/compare/v0.10.7...v0.10.8)

View File

@ -9,7 +9,7 @@ module ActiveModel
delegate :collection?, to: :reflection
def reflection_options
@reflection_options ||= reflection.options.dup.reject { |k, _| !REFLECTION_OPTIONS.include?(k) }
@reflection_options ||= reflection.options.select { |k, _| REFLECTION_OPTIONS.include?(k) }
end
def object

View File

@ -37,7 +37,7 @@ module ActiveModelSerializers
# @return [Array<Symbol>] list of adapter names
def adapters
adapter_map.keys.sort
adapter_map.keys.sort!
end
# Adds an adapter 'klass' with 'name' to the 'adapter_map'

View File

@ -16,8 +16,8 @@ module ActiveModelSerializers
# @return the serializable_resource, ready for #as_json/#to_json/#serializable_hash.
def initialize(resource, options = {})
@resource = resource
@adapter_opts, @serializer_opts =
options.partition { |k, _| ADAPTER_OPTION_KEYS.include? k }.map { |h| Hash[h] }
@adapter_opts = options.select { |k, _| ADAPTER_OPTION_KEYS.include? k }
@serializer_opts = options.reject { |k, _| ADAPTER_OPTION_KEYS.include? k }
end
def serialization_scope=(scope)