Skip to content

Commit

Permalink
fix a performance issue with dependent params
Browse files Browse the repository at this point in the history
Fixes #2100

The reason was in `ActiveSupport::HashWithIndifferentAccess`, it
is super expensive.

When users use `Grape::Extensions::ActiveSupport::HashWithIndifferentAccess::ParamBuilder`
or `Grape::Extensions::Hashie::Mash::ParamBuilder` as a parameter builder
there is no change. However, users who use `Grape::Extensions::Hash::ParamBuilder`
must make sure an attribute to be dependent on must be a symbol.

    given :matrix do
      # block here
    end
  • Loading branch information
dnesteryuk committed Oct 27, 2020
1 parent 1e97967 commit 8a2f942
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#### Fixes

* Your contribution here.
* [#](https://github.com/ruby-grape/grape/pull/): Fix performance issues with dependent params - [@dnesteryuk](https://github.com/dnesteryuk).
* [#2126](https://github.com/ruby-grape/grape/pull/2126): Fix warnings about redefined attribute accessors in `AttributeTranslator` - [@samsonjs](https://github.com/samsonjs).
* [#2121](https://github.com/ruby-grape/grape/pull/2121): Fix 2.7 deprecation warning in validator_factory - [@Legogris](https://github.com/Legogris).
* [#2115](https://github.com/ruby-grape/grape/pull/2115): Fix declared_params regression with multiple allowed types - [@stanhu](https://github.com/stanhu).
Expand Down
1 change: 0 additions & 1 deletion lib/grape/validations/params_scope.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ def meets_dependency?(params, request_params)

return params.any? { |param| meets_dependency?(param, request_params) } if params.is_a?(Array)
return false unless params.respond_to?(:with_indifferent_access)
params = params.with_indifferent_access

@dependent_on.each do |dependency|
if dependency.is_a?(Hash)
Expand Down

0 comments on commit 8a2f942

Please sign in to comment.