Skip to content

Commit 624175d

Browse files
authored
Stop creating indexes each time a document is inserted (#62)
* Stop creating indexes each time a document is inserted We shouldn't treat the underlying database as something we own but rather see this application as one of many application that interact with an Eiffel event store. From that point of view it doesn't make sense to create indexes each time a document is created. Although the fields we previously created indexes for should be indexed in pretty much any deployment most deployments will also want to index additional fields. Adding a configuration option to manage indexes in this application doesn't feel right, nor does spreading out index management in multiple places. Hence, remove index creations from insert_to_db(). This should also improve performance. * Fix formatting to please Black
1 parent ab63a84 commit 624175d

File tree

1 file changed

+1
-5
lines changed

1 file changed

+1
-5
lines changed

src/eiffel_graphql_api/graphql/db/database.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,11 @@ def insert_to_db(event, _=None):
115115
try:
116116
database = get_database()
117117
collection = database[event.meta.type]
118-
collection.create_index([("meta.id", pymongo.ASCENDING)])
119-
collection.create_index([("links.target", pymongo.ASCENDING)])
120118
doc = event.json
121119
doc["_id"] = event.meta.event_id
122120
collection.insert_one(doc)
123121
except pymongo.errors.DuplicateKeyError:
124-
LOGGER.warning(
125-
"Event already exists in the database, " "skipping: %r", event.json
126-
)
122+
LOGGER.warning("Event already exists in the database, skipping: %r", event.json)
127123
return True
128124
except pymongo.errors.ConnectionFailure as exception:
129125
LOGGER.warning("%r", exception)

0 commit comments

Comments
 (0)