Skip to content

Commit

Permalink
Update in memory context update to single db hit
Browse files Browse the repository at this point in the history
  • Loading branch information
durran committed May 27, 2012
1 parent 19fc642 commit 8eb0d71
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions lib/mongoid/contextual/memory.rb
Expand Up @@ -250,11 +250,14 @@ def sort(values)
#
# @since 3.0.0
def update(attributes = nil)
# @todo: Durran: Optimize to a single db call.
return false unless attributes
updates = {}
each do |doc|
doc.update_attributes(attributes)
@selector ||= root.atomic_selector
doc.write_attributes(attributes)
updates.merge!(doc.atomic_position => attributes)
end
collection.find(selector).update("$set" => updates)
end
alias :update_all :update

Expand Down Expand Up @@ -332,8 +335,6 @@ def apply_options

# Map the sort symbols to the correct MongoDB values.
#
# @todo: Durran: Temporary.
#
# @example Apply the sorting params.
# context.apply_sorting
#
Expand All @@ -346,8 +347,6 @@ def apply_sorting

# Sort the documents in place.
#
# @todo: Durran: Temporary until sorting is all refactored.
#
# @example Sort the documents.
# context.in_place_sort(name: 1)
#
Expand Down

0 comments on commit 8eb0d71

Please sign in to comment.