-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add auto_indexes feature to LazyInstance #82
Conversation
I think this could be addressed in @touilleMan , waiting for your feedback before going any further. This is not critical to us. |
I think this feature is pretty interesting given calling Few remarks:
class Instance:
...
def register(self, template):
# overload the default register to add a synchronous creation of indexes if needed
implementation = super().register(template)
if self.auto_indexes:
self.builder.ensure_indexes(implementation)
class LazyLoaderInstance:
...
def init(self, db):
...
# Now we can finish initialization of all the documents
for doc in self._doc_lookup.values():
self.builder.ensure_indexes(doc)
class PyMongoBuilder(BaseBuilder):
BASE_DOCUMENT_CLS = PyMongoDocument
...
def ensure_indexes(self, implementation):
# For async framework, we create a reactor just for this coroutine so
# we end up with something synchronous anyway
implementation.ensure_indexes()
instance = Instance(db, auto_indexes=False)
@instance.register(force_auto_indexes_value=True)
class MyDoc(Document):
... |
Thank you for your feedback.
I don't remember why I did not do it for
Good points.
|
I'm closing this because pymongo's ensure_index has been deprecated. This makes creating automatically indexes much more complicated (plenty of complex concurrency bugs there, that's the reason pymongo dropped the feature in the first place). For instance, this "don't bother user with this" approach created serious perf issues with mongoengine that are now complicated to fix. |
Closes #81.
What do you think about this ?
It works only on documents that are already registered when calling
instance.init()
.TODO:
Add tests for drivers other than PyMongo (currently only PyMongo is tested)
Document the feature
Also ensure indexes on documents registered after
instance.init()
?