Skip to content

Commit 9b2d02f

Browse files
committed
remove obsolete parts of query logging
1 parent 84d300a commit 9b2d02f

File tree

1 file changed

+4
-32
lines changed

1 file changed

+4
-32
lines changed

django_mongodb/utils.py

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from django.core.exceptions import ImproperlyConfigured
77
from django.db.backends.utils import logger
88
from django.utils.version import get_version_tuple
9-
from pymongo.cursor import Cursor
109

1110

1211
def check_django_compatability():
@@ -41,12 +40,11 @@ def profile_call(self, func, args=(), kwargs=None):
4140
return duration, retval
4241

4342
def log(self, op, duration, args, kwargs=None):
43+
# If kwargs are used by any operations in the future, they must be
44+
# added to this logging.
4445
msg = "(%.3f) %s"
4546
args = ", ".join(str(arg) for arg in args)
4647
operation = f"{self.collection.name}.{op}({args})"
47-
kwargs = {k: v for k, v in kwargs.items() if v}
48-
if kwargs:
49-
operation += f"; kwargs={kwargs}"
5048
if len(settings.DATABASES) > 1:
5149
msg += f"; alias={self.db.alias}"
5250
self.db.queries_log.append(
@@ -62,19 +60,15 @@ def log(self, op, duration, args, kwargs=None):
6260
extra={
6361
"duration": duration,
6462
"sql": operation,
65-
"kwargs": kwargs,
6663
"alias": self.db.alias,
6764
},
6865
)
6966

70-
def find(self, *args, **kwargs):
71-
return DebugCursor(self, self.collection, *args, **kwargs)
72-
7367
def logging_wrapper(method):
7468
def wrapper(self, *args, **kwargs):
7569
func = getattr(self.collection, method)
76-
# Collection.insert_one() mutates args[0] (the document) by adding
77-
# the _id. deepcopy() to avoid logging that version.
70+
# Collection.insert_many() mutates args (the documents) by adding
71+
# _id. deepcopy() to avoid logging that version.
7872
original_args = copy.deepcopy(args)
7973
duration, retval = self.profile_call(func, args, kwargs)
8074
self.log(method, duration, original_args, kwargs)
@@ -84,30 +78,8 @@ def wrapper(self, *args, **kwargs):
8478

8579
# These are the operations that this backend uses.
8680
aggregate = logging_wrapper("aggregate")
87-
count_documents = logging_wrapper("count_documents")
8881
insert_many = logging_wrapper("insert_many")
8982
delete_many = logging_wrapper("delete_many")
9083
update_many = logging_wrapper("update_many")
9184

9285
del logging_wrapper
93-
94-
95-
class DebugCursor(Cursor):
96-
def __init__(self, collection_wrapper, *args, **kwargs):
97-
self.collection_wrapper = collection_wrapper
98-
super().__init__(*args, **kwargs)
99-
100-
def _refresh(self):
101-
super_method = super()._refresh
102-
if self._Cursor__id is not None:
103-
return super_method()
104-
# self.__id is None: first time the .find() iterator is
105-
# entered. find() profiling happens here.
106-
duration, retval = self.collection_wrapper.profile_call(super_method)
107-
kwargs = {
108-
"limit": self._Cursor__limit,
109-
"skip": self._Cursor__skip,
110-
"sort": self._Cursor__ordering,
111-
}
112-
self.collection_wrapper.log("find", duration, [self._Cursor__spec], kwargs)
113-
return retval

0 commit comments

Comments
 (0)