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 @@ -407,7 +407,8 @@ def project_field(column):
407
407
def collection_name (self ):
408
408
return self .query .get_meta ().db_table
409
409
410
- def get_collection (self ):
410
+ @cached_property
411
+ def collection (self ):
411
412
return self .connection .get_collection (self .collection_name )
412
413
413
414
def get_lookup_pipeline (self ):
@@ -513,8 +514,7 @@ def execute_sql(self, returning_fields=None):
513
514
@wrap_database_errors
514
515
def insert (self , docs , returning_fields = None ):
515
516
"""Store a list of documents using field columns as element names."""
516
- collection = self .get_collection ()
517
- inserted_ids = collection .insert_many (docs ).inserted_ids
517
+ inserted_ids = self .collection .insert_many (docs ).inserted_ids
518
518
return inserted_ids if returning_fields else []
519
519
520
520
@@ -579,12 +579,11 @@ def update(self, values):
579
579
580
580
@wrap_database_errors
581
581
def execute_update (self , update_spec ):
582
- collection = self .get_collection ()
583
582
try :
584
583
criteria = self .build_query ().mongo_query
585
584
except EmptyResultSet :
586
585
return 0
587
- return collection .update_many (criteria , update_spec ).matched_count
586
+ return self . collection .update_many (criteria , update_spec ).matched_count
588
587
589
588
def check_query (self ):
590
589
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