This is an automated email from the ASF dual-hosted git repository. dill0wn pushed a commit to branch dw/8565 in repository https://gitbox.apache.org/repos/asf/allura.git
commit d85289719eda42874a8cae2718acdf406389185f Author: Dillon Walls <dillon.wa...@slashdotmedia.com> AuthorDate: Tue Jun 25 18:09:35 2024 -0400 use pymongo's create_index rather than ensure_index --- Allura/allura/command/show_models.py | 8 ++++---- Allura/allura/tests/test_commands.py | 20 +++++++++----------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/Allura/allura/command/show_models.py b/Allura/allura/command/show_models.py index b0b5fad19..7bffebffa 100644 --- a/Allura/allura/command/show_models.py +++ b/Allura/allura/command/show_models.py @@ -297,14 +297,14 @@ class EnsureIndexCommand(base.Command): # _id is always non-sparse and unique anyway del index_options['sparse'] del index_options['unique'] - collection.ensure_index(idx.index_spec, **index_options) + collection.create_index(idx.index_spec, **index_options) break except DuplicateKeyError as err: base.log.info('Found dupe key(%s), eliminating dupes', err) self._remove_dupes(collection, idx.index_spec) for keys, idx in indexes.items(): base.log.info('...... ensure %s:%s', collection.name, idx) - collection.ensure_index(idx.index_spec, background=True, **idx.index_options) + collection.create_index(idx.index_spec, background=True, **idx.index_options) # Drop obsolete indexes for iname, keys in prev_indexes.items(): if keys not in indexes: @@ -329,12 +329,12 @@ class EnsureIndexCommand(base.Command): superset_keys = keys + [('temporary_extra_field_for_indexing', 1)] base.log.info('...... ensure index %s:%s', collection.name, superset_keys) - superset_index = collection.ensure_index(superset_keys) + superset_index = collection.create_index(superset_keys) base.log.info('...... drop index %s:%s', collection.name, iname) collection.drop_index(iname) base.log.info('...... ensure index %s:%s %s', collection.name, keys, creation_options) - collection.ensure_index(keys, **creation_options) + collection.create_index(keys, **creation_options) base.log.info('...... drop index %s:%s', collection.name, superset_index) collection.drop_index(superset_index) diff --git a/Allura/allura/tests/test_commands.py b/Allura/allura/tests/test_commands.py index 660b0f172..068fdaf89 100644 --- a/Allura/allura/tests/test_commands.py +++ b/Allura/allura/tests/test_commands.py @@ -199,7 +199,7 @@ class TestEnsureIndexCommand: cmd = show_models.EnsureIndexCommand('ensure_index') cmd.options = Object(clean=False) cmd._update_indexes(collection, indexes) - assert collection.ensure_index.called + assert collection.create_index.called assert not collection.drop_index.called def test_update_indexes_order(self): @@ -220,13 +220,13 @@ class TestEnsureIndexCommand: for i, call_ in enumerate(collection.mock_calls): method_name = call_[0] collection_call_order[method_name] = i - assert collection_call_order['ensure_index'] < collection_call_order['drop_index'], collection.mock_calls + assert collection_call_order['create_index'] < collection_call_order['drop_index'], collection.mock_calls def test_update_indexes_unique_changes(self): collection = Mock(name='collection') # expecting these ensure_index calls, we'll make their return values normal # for easier assertions later - collection.ensure_index.side_effect = [ + collection.create_index.side_effect = [ '_foo_bar_temporary_extra_field_for_indexing', '_foo_bar', '_foo_baz_temporary_extra_field_for_indexing', @@ -251,18 +251,16 @@ class TestEnsureIndexCommand: assert collection.mock_calls == [ call.index_information(), - call.ensure_index( - [('foo', 1), ('bar', 1), ('temporary_extra_field_for_indexing', 1)]), + call.create_index([('foo', 1), ('bar', 1), ('temporary_extra_field_for_indexing', 1)]), call.drop_index('_foo_bar'), - call.ensure_index([('foo', 1), ('bar', 1)], unique=False), + call.create_index([('foo', 1), ('bar', 1)], unique=False), call.drop_index('_foo_bar_temporary_extra_field_for_indexing'), - call.ensure_index( - [('foo', 1), ('baz', 1), ('temporary_extra_field_for_indexing', 1)]), + call.create_index([('foo', 1), ('baz', 1), ('temporary_extra_field_for_indexing', 1)]), call.drop_index('_foo_baz'), - call.ensure_index([('foo', 1), ('baz', 1)], unique=True), + call.create_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, sparse=False), - call.ensure_index([('foo', 1), ('bar', 1)], unique=False, sparse=False, background=True) + call.create_index([('foo', 1), ('baz', 1)], unique=True, sparse=False), + call.create_index([('foo', 1), ('bar', 1)], unique=False, sparse=False, background=True) ]