Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'vandrijevik/master'

Conflicts:
	lib/mongo_mapper/plugins/identity_map.rb
  • Loading branch information...
commit 6f7754c3f6e8237f65c69199bce337fd0a2cce48 2 parents b4aefa9 + 8820194
@jnunemaker jnunemaker authored
Showing with 7 additions and 8 deletions.
  1. +7 −8 lib/mongo_mapper/plugins/identity_map.rb
View
15 lib/mongo_mapper/plugins/identity_map.rb
@@ -44,15 +44,10 @@ def identity_map=(v)
end
def find_one(options={})
- criteria, finder_options = to_finder_options(options)
- document_in_map = identity_map[criteria[:_id]]
- find_by_single_id = criteria.keys == [:_id]
- find_by_single_id_with_sci = criteria.keys.to_set == [:_id, :_type].to_set
+ criteria, finder_options = to_finder_options(options)
- if find_by_single_id && document_in_map
- document_in_map
- elsif find_by_single_id_with_sci && document_in_map
- document_in_map
+ if simple_find?(criteria) && identity_map.key?(criteria[:_id])
+ identity_map[criteria[:_id]]
else
super.tap do |document|
remove_documents_from_map(document) unless finder_options[:fields].nil?
@@ -91,6 +86,10 @@ def remove_documents_from_map(*documents)
identity_map.delete(document._id)
end
end
+
+ def simple_find?(criteria)
+ criteria.keys == [:_id] || criteria.keys.to_set == [:_id, :_type].to_set
+ end
end
module InstanceMethods
Please sign in to comment.
Something went wrong with that request. Please try again.