Skip to content
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

Singleton connection to database #21

Open
jearistiz opened this issue Apr 22, 2021 · 2 comments · Fixed by #20
Open

Singleton connection to database #21

jearistiz opened this issue Apr 22, 2021 · 2 comments · Fixed by #20
Labels
help wanted Extra attention is needed question Further information is requested

Comments

@jearistiz
Copy link
Member

jearistiz commented Apr 22, 2021

Connection to mongodb could be done by means of a singleton. Verify if this is needed, and implement the singleton if needed.

@jearistiz
Copy link
Member Author

Singleton pattern is probably not a good idea when using pymongo: https://pymongo.readthedocs.io/en/stable/faq.html#using-pymongo-with-multiprocessing

@jearistiz jearistiz added help wanted Extra attention is needed question Further information is requested labels Apr 22, 2021
@jearistiz jearistiz changed the title Define if singleton connection to database is needed Singleton connection to database? Apr 22, 2021
@jearistiz jearistiz changed the title Singleton connection to database? Singleton connection to database Apr 24, 2021
jearistiz added a commit that referenced this issue Apr 25, 2021
Issue/9/insert cmodels in database

This PR was initially opened to address issue #9. However The issue was indirectly related to these other issues that will also be closed. 

closes #9
closes #23
closes #10
closes #21
@jearistiz
Copy link
Member Author

jearistiz commented Apr 25, 2021

Patterns I Hate # 1: Singleton

We already implemented the singleton but there are a lot of bad comments on this practice, even when using it for DB connections. The best alternative is just creating one instance of the db connection and pass it to all parts of code that need it.

The code will be easy to refactor given the current circumstances. We just get rid of the Singleton inheritance in MongoClientSingleton and rename some variables.

@jearistiz jearistiz reopened this Apr 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant