Skip to content

Commit 863f1c9

Browse files
rmsrbehackett
authored andcommitted
speed up python-only batch inserts
1 parent 159c29f commit 863f1c9

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

pymongo/message.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,9 @@ def insert(collection_name, docs, check_keys, safe, last_error_args):
6868
max_bson_size = 0
6969
data = __ZERO
7070
data += bson._make_c_string(collection_name)
71-
bson_data = ""
72-
for doc in docs:
73-
encoded = bson.BSON.encode(doc, check_keys)
74-
bson_data += encoded
75-
max_bson_size = max(len(encoded), max_bson_size)
71+
encoded = [ bson.BSON.encode(doc, check_keys) for doc in docs ]
72+
max_bson_size = max(map(len, encoded))
73+
bson_data = "".join(encoded)
7674
if not bson_data:
7775
raise InvalidOperation("cannot do an empty bulk insert")
7876
data += bson_data

0 commit comments

Comments
 (0)