Skip to content

Commit

Permalink
Performance and memory usage fixes (#2309)
Browse files Browse the repository at this point in the history
* Use select and reject instead of partition.map

* Sort adapters keys in place

* Just select from options

* Add changelog entry
  • Loading branch information
krzysiek1507 authored and bf4 committed Jan 29, 2019
1 parent 22f2cb7 commit 209834d
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion lib/active_model/serializer/lazy_association.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Serializer
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
Expand Down
2 changes: 1 addition & 1 deletion lib/active_model_serializers/adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def adapter_map

# @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'
Expand Down
4 changes: 2 additions & 2 deletions lib/active_model_serializers/serializable_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ class SerializableResource
# @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)
Expand Down

0 comments on commit 209834d

Please sign in to comment.