File tree Expand file tree Collapse file tree 2 files changed +5
-6
lines changed Expand file tree Collapse file tree 2 files changed +5
-6
lines changed Original file line number Diff line number Diff line change @@ -409,7 +409,8 @@ def project_field(column):
409
409
def collection_name (self ):
410
410
return self .query .get_meta ().db_table
411
411
412
- def get_collection (self ):
412
+ @cached_property
413
+ def collection (self ):
413
414
return self .connection .get_collection (self .collection_name )
414
415
415
416
def get_lookup_pipeline (self ):
@@ -516,8 +517,7 @@ def execute_sql(self, returning_fields=None):
516
517
@wrap_database_errors
517
518
def insert (self , docs , returning_fields = None ):
518
519
"""Store a list of documents using field columns as element names."""
519
- collection = self .get_collection ()
520
- inserted_ids = collection .insert_many (docs ).inserted_ids
520
+ inserted_ids = self .collection .insert_many (docs ).inserted_ids
521
521
return inserted_ids if returning_fields else []
522
522
523
523
@@ -582,12 +582,11 @@ def update(self, values):
582
582
583
583
@wrap_database_errors
584
584
def execute_update (self , update_spec ):
585
- collection = self .get_collection ()
586
585
try :
587
586
criteria = self .build_query ().mongo_query
588
587
except EmptyResultSet :
589
588
return 0
590
- return collection .update_many (criteria , update_spec ).matched_count
589
+ return self . collection .update_many (criteria , update_spec ).matched_count
591
590
592
591
def check_query (self ):
593
592
super ().check_query ()
Original file line number Diff line number Diff line change @@ -43,7 +43,7 @@ def __init__(self, compiler):
43
43
self .query = compiler .query
44
44
self ._negated = False
45
45
self .ordering = []
46
- self .collection = self .compiler .get_collection ()
46
+ self .collection = self .compiler .collection
47
47
self .collection_name = self .compiler .collection_name
48
48
self .mongo_query = getattr (compiler .query , "raw_query" , {})
49
49
self .subquery = None
You can’t perform that action at this time.
0 commit comments