reinsert fix; add comments, reference
This commit is contained in:
parent
4ccfdf051d
commit
61081651e4
@ -1200,7 +1200,11 @@ class BaseQuerySet(object):
|
|||||||
initial_pipeline.append({'$sort': dict(self._ordering)})
|
initial_pipeline.append({'$sort': dict(self._ordering)})
|
||||||
|
|
||||||
if self._limit is not None:
|
if self._limit is not None:
|
||||||
initial_pipeline.append({'$limit': self._limit})
|
# As per MongoDB Documentation (https://docs.mongodb.com/manual/reference/operator/aggregation/limit/),
|
||||||
|
# keeping limit stage right after sort stage is more efficient. But this leads to wrong set of documents
|
||||||
|
# for a skip stage that might succeed these. So we need to maintain more documents in memory in such a
|
||||||
|
# case (https://stackoverflow.com/a/24161461).
|
||||||
|
initial_pipeline.append({'$limit': self._limit + (self._skip or 0)})
|
||||||
|
|
||||||
if self._skip is not None:
|
if self._skip is not None:
|
||||||
initial_pipeline.append({'$skip': self._skip})
|
initial_pipeline.append({'$skip': self._skip})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user