Added QuerySetNoCache and QuerySet.no_cache() for lower memory consumption (#365)
This commit is contained in:
parent
8131f0a752
commit
634b874c46
@ -49,6 +49,11 @@ Querying
|
|||||||
|
|
||||||
.. automethod:: mongoengine.queryset.QuerySet.__call__
|
.. automethod:: mongoengine.queryset.QuerySet.__call__
|
||||||
|
|
||||||
|
.. autoclass:: mongoengine.queryset.QuerySetNoCache
|
||||||
|
:members:
|
||||||
|
|
||||||
|
.. automethod:: mongoengine.queryset.QuerySetNoCache.__call__
|
||||||
|
|
||||||
.. autofunction:: mongoengine.queryset.queryset_manager
|
.. autofunction:: mongoengine.queryset.queryset_manager
|
||||||
|
|
||||||
Fields
|
Fields
|
||||||
|
@ -4,6 +4,7 @@ Changelog
|
|||||||
|
|
||||||
Changes in 0.8.3
|
Changes in 0.8.3
|
||||||
================
|
================
|
||||||
|
- Added QuerySetNoCache and QuerySet.no_cache() for lower memory consumption (#365)
|
||||||
- Fixed sum and average mapreduce dot notation support (#375, #376)
|
- Fixed sum and average mapreduce dot notation support (#375, #376)
|
||||||
- Fixed as_pymongo to return the id (#386)
|
- Fixed as_pymongo to return the id (#386)
|
||||||
- Document.select_related() now respects `db_alias` (#377)
|
- Document.select_related() now respects `db_alias` (#377)
|
||||||
|
@ -16,7 +16,9 @@ fetch documents from the database::
|
|||||||
.. note::
|
.. note::
|
||||||
|
|
||||||
As of MongoEngine 0.8 the querysets utilise a local cache. So iterating
|
As of MongoEngine 0.8 the querysets utilise a local cache. So iterating
|
||||||
it multiple times will only cause a single query.
|
it multiple times will only cause a single query. If this is not the
|
||||||
|
desired behavour you can call :class:`~mongoengine.QuerySet.no_cache` to
|
||||||
|
return a non-caching queryset.
|
||||||
|
|
||||||
Filtering queries
|
Filtering queries
|
||||||
=================
|
=================
|
||||||
|
1479
mongoengine/queryset/base.py
Normal file
1479
mongoengine/queryset/base.py
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -3254,7 +3254,7 @@ class QuerySetTest(unittest.TestCase):
|
|||||||
User(name="Barack Obama", age=51, price=Decimal('2.22')).save()
|
User(name="Barack Obama", age=51, price=Decimal('2.22')).save()
|
||||||
|
|
||||||
results = User.objects.only('id', 'name').as_pymongo()
|
results = User.objects.only('id', 'name').as_pymongo()
|
||||||
self.assertEqual(results[0].keys(), ['_id', 'name'])
|
self.assertEqual(sorted(results[0].keys()), sorted(['_id', 'name']))
|
||||||
|
|
||||||
users = User.objects.only('name', 'price').as_pymongo()
|
users = User.objects.only('name', 'price').as_pymongo()
|
||||||
results = list(users)
|
results = list(users)
|
||||||
@ -3365,6 +3365,34 @@ class QuerySetTest(unittest.TestCase):
|
|||||||
self.assertEqual("%s" % users, "[<User: Bob>]")
|
self.assertEqual("%s" % users, "[<User: Bob>]")
|
||||||
self.assertEqual(1, len(users._result_cache))
|
self.assertEqual(1, len(users._result_cache))
|
||||||
|
|
||||||
|
def test_no_cache(self):
|
||||||
|
"""Ensure you can add meta data to file"""
|
||||||
|
|
||||||
|
class Noddy(Document):
|
||||||
|
fields = DictField()
|
||||||
|
|
||||||
|
Noddy.drop_collection()
|
||||||
|
for i in xrange(100):
|
||||||
|
noddy = Noddy()
|
||||||
|
for j in range(20):
|
||||||
|
noddy.fields["key"+str(j)] = "value "+str(j)
|
||||||
|
noddy.save()
|
||||||
|
|
||||||
|
docs = Noddy.objects.no_cache()
|
||||||
|
|
||||||
|
counter = len([1 for i in docs])
|
||||||
|
self.assertEquals(counter, 100)
|
||||||
|
|
||||||
|
self.assertEquals(len(list(docs)), 100)
|
||||||
|
self.assertRaises(TypeError, lambda: len(docs))
|
||||||
|
|
||||||
|
with query_counter() as q:
|
||||||
|
self.assertEqual(q, 0)
|
||||||
|
list(docs)
|
||||||
|
self.assertEqual(q, 1)
|
||||||
|
list(docs)
|
||||||
|
self.assertEqual(q, 2)
|
||||||
|
|
||||||
def test_nested_queryset_iterator(self):
|
def test_nested_queryset_iterator(self):
|
||||||
# Try iterating the same queryset twice, nested.
|
# Try iterating the same queryset twice, nested.
|
||||||
names = ['Alice', 'Bob', 'Chuck', 'David', 'Eric', 'Francis', 'George']
|
names = ['Alice', 'Bob', 'Chuck', 'David', 'Eric', 'Francis', 'George']
|
||||||
|
Loading…
x
Reference in New Issue
Block a user