You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2015/10/05 21:38:34 UTC
[2/2] allura git commit: [#7991] Add sparse index for
phone_verification.number_hash
[#7991] Add sparse index for phone_verification.number_hash
Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/c8300e12
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/c8300e12
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/c8300e12
Branch: refs/heads/db/7991
Commit: c8300e128dd3b6c936ce9dacbe88da10b04c05d6
Parents: 0323078
Author: Dave Brondsema <da...@brondsema.net>
Authored: Mon Oct 5 12:05:40 2015 -0400
Committer: Dave Brondsema <da...@brondsema.net>
Committed: Mon Oct 5 15:38:26 2015 -0400
----------------------------------------------------------------------
Allura/allura/command/show_models.py | 10 ++++------
Allura/allura/model/auth.py | 3 +++
Allura/allura/tests/test_commands.py | 13 ++++++++-----
3 files changed, 15 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/allura/blob/c8300e12/Allura/allura/command/show_models.py
----------------------------------------------------------------------
diff --git a/Allura/allura/command/show_models.py b/Allura/allura/command/show_models.py
index 89a2a88..d651383 100644
--- a/Allura/allura/command/show_models.py
+++ b/Allura/allura/command/show_models.py
@@ -282,24 +282,22 @@ class EnsureIndexCommand(base.Command):
base.log.info('...... ensure %s:%s', collection.name, idx)
while True:
try:
- collection.ensure_index(idx.index_spec, unique=True)
+ collection.ensure_index(idx.index_spec, **idx.index_options)
break
except DuplicateKeyError, err:
base.log.info('Found dupe key(%s), eliminating dupes', err)
self._remove_dupes(collection, idx.index_spec)
for keys, idx in indexes.iteritems():
base.log.info('...... ensure %s:%s', collection.name, idx)
- collection.ensure_index(idx.index_spec, background=True)
+ collection.ensure_index(idx.index_spec, background=True, **idx.index_options)
# Drop obsolete indexes
for iname, keys in prev_indexes.iteritems():
if keys not in indexes:
- base.log.info('...... drop index %s:%s',
- collection.name, iname)
+ base.log.info('...... drop index %s:%s', collection.name, iname)
collection.drop_index(iname)
for iname, keys in prev_uindexes.iteritems():
if keys not in uindexes:
- base.log.info('...... drop index %s:%s',
- collection.name, iname)
+ base.log.info('...... drop index %s:%s', collection.name, iname)
collection.drop_index(iname)
def _recreate_index(self, collection, iname, keys, **creation_options):
http://git-wip-us.apache.org/repos/asf/allura/blob/c8300e12/Allura/allura/model/auth.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/auth.py b/Allura/allura/model/auth.py
index 163d5de..955c952 100644
--- a/Allura/allura/model/auth.py
+++ b/Allura/allura/model/auth.py
@@ -272,6 +272,9 @@ class User(MappedClass, ActivityNode, ActivityObject, SearchIndexable):
session = main_orm_session
indexes = ['tool_data.sfx.userid', 'tool_data.AuthPasswordReset.hash']
unique_indexes = ['username']
+ custom_indexes = [
+ dict(fields=('tool_data.phone_verification.number_hash',), sparse=True),
+ ]
type_s = 'User'
http://git-wip-us.apache.org/repos/asf/allura/blob/c8300e12/Allura/allura/tests/test_commands.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_commands.py b/Allura/allura/tests/test_commands.py
index f6800b7..fb5fb03 100644
--- a/Allura/allura/tests/test_commands.py
+++ b/Allura/allura/tests/test_commands.py
@@ -187,7 +187,8 @@ class TestEnsureIndexCommand(object):
'_foo_bar': {'key': [('foo', 1), ('bar', 1)]},
}
indexes = [
- Mock(unique=False, index_spec=[('foo', 1)]),
+ Mock(unique=False, index_spec=[('foo', 1)],
+ index_options={'unique': False, 'sparse': False}),
]
cmd = show_models.EnsureIndexCommand('ensure_index')
cmd._update_indexes(collection, indexes)
@@ -216,8 +217,10 @@ class TestEnsureIndexCommand(object):
'_foo_baz': {'key': [('foo', 1), ('baz', 1)]},
}
indexes = [
- Mock(index_spec=[('foo', 1), ('bar', 1)], unique=False, ),
- Mock(index_spec=[('foo', 1), ('baz', 1)], unique=True, ),
+ Mock(index_spec=[('foo', 1), ('bar', 1)], unique=False,
+ index_options={'unique': False, 'sparse': False}),
+ Mock(index_spec=[('foo', 1), ('baz', 1)], unique=True,
+ index_options={'unique': True, 'sparse': False}),
]
cmd = show_models.EnsureIndexCommand('ensure_index')
@@ -235,8 +238,8 @@ class TestEnsureIndexCommand(object):
call.drop_index('_foo_baz'),
call.ensure_index([('foo', 1), ('baz', 1)], unique=True),
call.drop_index('_foo_baz_temporary_extra_field_for_indexing'),
- call.ensure_index([('foo', 1), ('baz', 1)], unique=True),
- call.ensure_index([('foo', 1), ('bar', 1)], background=True)
+ call.ensure_index([('foo', 1), ('baz', 1)], unique=True, sparse=False),
+ call.ensure_index([('foo', 1), ('bar', 1)], unique=False, sparse=False, background=True)
])