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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user