fenfisdi / cdslab_cmodels_api

cmodels API repo
GNU General Public License v3.0
0 stars 0 forks source link

Singleton connection to database #21

Open jearistiz opened 3 years ago

jearistiz commented 3 years ago

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

jearistiz commented 3 years ago

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

jearistiz commented 3 years ago

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.