Ensure that the update actions are grouped rather than serial.

This is a performance update. When multiple properties of the same
entity have been deleted and modified, 2 calls to update the entity are
made, one {"$set": … } and another {"$unset": … }. This is 2 network
interface calls which is a performance killer (even at lan speeds).

Fixes: #210
This commit is contained in:
Nick Joyce
2013-01-07 14:49:39 +00:00
committed by Nick Joyce
parent e537369d98
commit 7bb9c7d47f
2 changed files with 38 additions and 3 deletions

View File

@@ -234,11 +234,16 @@ class Document(BaseDocument):
select_dict[actual_key] = doc[actual_key]
upsert = self._created
work = {}
if updates:
collection.update(select_dict, {"$set": updates},
upsert=upsert, safe=safe, **write_options)
work["$set"] = updates
if removals:
collection.update(select_dict, {"$unset": removals},
work["$unset"] = removals
if work:
collection.update(select_dict, work,
upsert=upsert, safe=safe, **write_options)
warn_cascade = not cascade and 'cascade' not in self._meta