Skip to content

Commit

Permalink
Merge pull request #51 from Kezzsim/index_optimization
Browse files Browse the repository at this point in the history
Change index creation time from being on connect to on create
  • Loading branch information
danielballan authored Apr 1, 2024
2 parents e098c48 + dcfac69 commit 317b70c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 10 deletions.
3 changes: 1 addition & 2 deletions suitcase/mongo_normalized/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,8 @@ def __init__(
self._asset_registry_db = assets_db
self._ignore_duplicates = ignore_duplicates
self._resource_uid_unique = resource_uid_unique
self._create_indexes()

def _create_indexes(self):
def create_indexes(self):
"""
Create indexes on the various collections.
Expand Down
2 changes: 1 addition & 1 deletion suitcase/mongo_normalized/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
from ophyd.tests.conftest import hw # noqa
from suitcase.utils.tests.conftest import ( # noqa
example_data, generate_data, plan_type, detector_list, event_type)
from .fixtures import db_factory # noqa
from .fixtures import db_factory, db_factory_no_indexes # noqa
22 changes: 21 additions & 1 deletion suitcase/mongo_normalized/tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,23 @@
import mongomock
import pytest
import uuid
from suitcase.mongo_normalized import Serializer


@pytest.fixture()
def db_factory_no_indexes(request):
def inner():
database_name = f'test-{str(uuid.uuid4())}'
uri = 'mongodb://localhost:27017/'
client = mongomock.MongoClient(uri)
db = client[database_name]

def drop():
client.drop_database(database_name)

request.addfinalizer(drop)
return db
return inner


@pytest.fixture()
Expand All @@ -12,10 +29,13 @@ def inner():
database_name = f'test-{str(uuid.uuid4())}'
uri = 'mongodb://localhost:27017/'
client = mongomock.MongoClient(uri)
db = client[database_name]
serializer = Serializer(db, db)
serializer.create_indexes()

def drop():
client.drop_database(database_name)

request.addfinalizer(drop)
return client[database_name]
return db
return inner
11 changes: 5 additions & 6 deletions suitcase/mongo_normalized/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def test_duplicates(db_factory, example_data):
metadatastore_db = db_factory()
asset_registry_db = db_factory()
serializer = Serializer(metadatastore_db, asset_registry_db)

for item in documents:
serializer(*item)
for item in documents:
Expand Down Expand Up @@ -204,12 +205,10 @@ def test_index_creation(db_factory):
assert indexes["descriptor_-1_time_1"]


def test_resource_uid_unique(db_factory):
db = db_factory()
print(type(db))
metadatastore_db = db_factory()
asset_registry_db = db_factory()
Serializer(metadatastore_db, asset_registry_db, resource_uid_unique=True)
def test_resource_uid_unique(db_factory_no_indexes):
metadatastore_db = db_factory_no_indexes()
asset_registry_db = db_factory_no_indexes()
Serializer(metadatastore_db, asset_registry_db, resource_uid_unique=True).create_indexes()

indexes = asset_registry_db.resource.index_information()
assert indexes["uid_1"].get("unique")

0 comments on commit 317b70c

Please sign in to comment.