Merge remote branch 'origin/dev' into dev
This commit is contained in:
commit
28b7ef2304
@ -53,6 +53,11 @@ class Document(BaseDocument):
|
|||||||
dictionary. The value should be a list of field names or tuples of field
|
dictionary. The value should be a list of field names or tuples of field
|
||||||
names. Index direction may be specified by prefixing the field names with
|
names. Index direction may be specified by prefixing the field names with
|
||||||
a **+** or **-** sign.
|
a **+** or **-** sign.
|
||||||
|
|
||||||
|
By default, _types will be added to the start of every index (that
|
||||||
|
doesn't contain a list) if allow_inheritence is True. This can be
|
||||||
|
disabled by either setting types to False on the specific index or
|
||||||
|
by setting index_types to False on the meta dictionary for the document.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__metaclass__ = TopLevelDocumentMetaclass
|
__metaclass__ = TopLevelDocumentMetaclass
|
||||||
|
@ -418,8 +418,9 @@ class QuerySet(object):
|
|||||||
use_types = False
|
use_types = False
|
||||||
|
|
||||||
# If _types is being used, prepend it to every specified index
|
# If _types is being used, prepend it to every specified index
|
||||||
if (spec.get('types', True) and doc_cls._meta.get('allow_inheritance')
|
index_types = doc_cls._meta.get('index_types', True)
|
||||||
and use_types):
|
allow_inheritance = doc_cls._meta.get('allow_inheritance')
|
||||||
|
if spec.get('types', index_types) and allow_inheritance and use_types:
|
||||||
index_list.insert(0, ('_types', 1))
|
index_list.insert(0, ('_types', 1))
|
||||||
|
|
||||||
spec['fields'] = index_list
|
spec['fields'] = index_list
|
||||||
@ -474,6 +475,7 @@ class QuerySet(object):
|
|||||||
background = self._document._meta.get('index_background', False)
|
background = self._document._meta.get('index_background', False)
|
||||||
drop_dups = self._document._meta.get('index_drop_dups', False)
|
drop_dups = self._document._meta.get('index_drop_dups', False)
|
||||||
index_opts = self._document._meta.get('index_options', {})
|
index_opts = self._document._meta.get('index_options', {})
|
||||||
|
index_types = self._document._meta.get('index_types', True)
|
||||||
|
|
||||||
# Ensure indexes created by uniqueness constraints
|
# Ensure indexes created by uniqueness constraints
|
||||||
for index in self._document._meta['unique_indexes']:
|
for index in self._document._meta['unique_indexes']:
|
||||||
@ -490,7 +492,7 @@ class QuerySet(object):
|
|||||||
background=background, **opts)
|
background=background, **opts)
|
||||||
|
|
||||||
# If _types is being used (for polymorphism), it needs an index
|
# If _types is being used (for polymorphism), it needs an index
|
||||||
if '_types' in self._query:
|
if index_types and '_types' in self._query:
|
||||||
self._collection.ensure_index('_types',
|
self._collection.ensure_index('_types',
|
||||||
background=background, **index_opts)
|
background=background, **index_opts)
|
||||||
|
|
||||||
|
@ -1830,6 +1830,22 @@ class QuerySetTest(unittest.TestCase):
|
|||||||
self.assertTrue([('_types', 1)] in info)
|
self.assertTrue([('_types', 1)] in info)
|
||||||
self.assertTrue([('_types', 1), ('date', -1)] in info)
|
self.assertTrue([('_types', 1), ('date', -1)] in info)
|
||||||
|
|
||||||
|
def test_dont_index_types(self):
|
||||||
|
"""Ensure that index_types will, when disabled, prevent _types
|
||||||
|
being added to all indices.
|
||||||
|
"""
|
||||||
|
class BlogPost(Document):
|
||||||
|
date = DateTimeField()
|
||||||
|
meta = {'index_types': False,
|
||||||
|
'indexes': ['-date']}
|
||||||
|
|
||||||
|
# Indexes are lazy so use list() to perform query
|
||||||
|
list(BlogPost.objects)
|
||||||
|
info = BlogPost.objects._collection.index_information()
|
||||||
|
info = [value['key'] for key, value in info.iteritems()]
|
||||||
|
self.assertTrue([('_types', 1)] not in info)
|
||||||
|
self.assertTrue([('date', -1)] in info)
|
||||||
|
|
||||||
BlogPost.drop_collection()
|
BlogPost.drop_collection()
|
||||||
|
|
||||||
class BlogPost(Document):
|
class BlogPost(Document):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user