Skip to content

Commit 1a66abf

Browse files
committed
Updated yield, fixed lints, rewrote docs to speak more high-level
1 parent 968946a commit 1a66abf

File tree

4 files changed

+17
-17
lines changed

4 files changed

+17
-17
lines changed

django_mongodb_backend/compiler.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@
1818

1919
from .query import MongoQuery, wrap_database_errors
2020

21-
# Maximum document batch size for MongoDB cursor responses.
22-
MAX_BATCH_SIZE_MB = 1024 * 1024 * 16
23-
2421

2522
class SQLCompiler(compiler.SQLCompiler):
2623
"""Base class for all Mongo compilers."""
@@ -321,15 +318,13 @@ def _make_result(self, entity, columns):
321318
def cursor_iter(self, cursor, _, columns):
322319
"""
323320
Yield chunks of results from cursor.
324-
MongoDB ignores all chunk_size overrides. Cursor iteration abides by
325-
MongoDB's default cursor batch size response.
321+
Ignore any chunk_size/batch_size overrides and abide by MongoDB's
322+
default chunking behavior. This maximizes performance on document
323+
retrieval.
326324
Read more here: https://www.mongodb.com/docs/manual/core/cursors/#cursor-batches
327325
"""
328-
chunk = []
329-
330326
for row in cursor:
331-
chunk.append(self._make_result(row, columns))
332-
return chunk
327+
yield [self._make_result(row, columns)]
333328

334329
def check_query(self):
335330
"""Check if the current query is supported by the database."""

django_mongodb_backend/query.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ def get_cursor(self):
7676
"""
7777
self.compiler.connection.validate_no_broken_transaction()
7878
return self.compiler.collection.aggregate(
79-
self.get_pipeline(),
80-
session=self.compiler.connection.session,
79+
self.get_pipeline(), session=self.compiler.connection.session
8180
)
8281

8382
def get_pipeline(self):

docs/source/releases/5.1.x.rst

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,18 @@ Django MongoDB Backend 5.1.x
77

88
*Unreleased*
99

10+
11+
Bug fixes
12+
---------
13+
1014
- Fixed crash when loading models with a null value for ``ArrayField``\s where
1115
the ``base_field`` uses a database converter.
1216
- Fixed ``RecursionError`` when using ``Trunc`` database functions on non-MongoDB
1317
databases.
14-
- Removed ``GET_ITERATOR_CHUNK_SIZE`` as default from
15-
:meth:`SQLCompiler.execute_sql() <django_mongodb_backend.compiler.SQLCompiler.execute_sql>`.
16-
Cursor iteration will now use MongoDB default batch sizing.
18+
- Removed user configurable request chunking. Allowing MongoDB to
19+
handle chunking automatically improves performance and reduces complexity.
20+
As a result, :meth:`QuerySet.iterator() <django.db.models.query.QuerySet.iterator>`
21+
ignores the ``chunk_size`` parameter.
1722

1823

1924
5.1.0 beta 3

docs/source/releases/5.2.x.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@ Bug fixes
2424
databases.
2525
- :meth:`QuerySet.explain() <django.db.models.query.QuerySet.explain>` now
2626
:ref:`returns a string that can be parsed as JSON <queryset-explain>`.
27-
- Removed ``GET_ITERATOR_CHUNK_SIZE`` as default from
28-
:meth:`SQLCompiler.execute_sql() <django_mongodb_backend.compiler.SQLCompiler.execute_sql>`.
29-
Cursor iteration will now use MongoDB default batch sizing.
27+
- Removed user configurable request chunking. Allowing MongoDB to
28+
handle chunking automatically improves performance and reduces complexity.
29+
As a result, :meth:`QuerySet.iterator() <django.db.models.query.QuerySet.iterator>`
30+
ignores the ``chunk_size`` parameter.
3031

3132

3233
5.2.0 beta 1

0 commit comments

Comments
 (0)