diff --git a/CHANGELOG.rdoc b/CHANGELOG.rdoc index 35b3bcd6..a7cdd574 100644 --- a/CHANGELOG.rdoc +++ b/CHANGELOG.rdoc @@ -2,6 +2,10 @@ Develop Unreleased +1.17.0 (March 26th, 2017) + +* Improve performance for the Mongoid Adapter + 1.16.0 (February 2nd, 2017) * Introduce rubocop and fixes most of the issues diff --git a/lib/cancan/model_adapters/mongoid_adapter.rb b/lib/cancan/model_adapters/mongoid_adapter.rb index 1771de11..87eff16b 100644 --- a/lib/cancan/model_adapters/mongoid_adapter.rb +++ b/lib/cancan/model_adapters/mongoid_adapter.rb @@ -62,7 +62,7 @@ def simplify_relations(model_class, conditions) if (relation = model_relations[k]) relation_class_name = relation[:class_name].blank? ? k.to_s.classify : relation[:class_name] v = simplify_relations(relation_class_name.constantize, v) - relation_ids = relation_class_name.constantize.where(v).only(:id).map(&:id) + relation_ids = relation_class_name.constantize.where(v).distinct(:_id) k = "#{k}_id" v = { '$in' => relation_ids } end diff --git a/lib/cancan/version.rb b/lib/cancan/version.rb index 43042322..79171d34 100644 --- a/lib/cancan/version.rb +++ b/lib/cancan/version.rb @@ -1,3 +1,3 @@ module CanCan - VERSION = '1.16.0'.freeze + VERSION = '1.17.0'.freeze end