IMAP-Science-Operations-Center / sds-data-manager

MIT License
0 stars 9 forks source link

MNT: Pass around database session rather than creating new ones #307

Closed greglucas closed 1 day ago

greglucas commented 6 days ago

Change Summary

Overview

We can refactor the database session handling to always begin with the lambda handler and then pass the session into all of the querying functions. This speeds up the database access by keeping the same connection alive for all queries rather than requesting a new one each time. This also makes the tests easier to mock and inject our test sessions by patching the module-level session factory.

Testing

Rather than using a fixture to populate the databases, I switched it over to explicitly call the function from within the test so that we are only populating what needs to be populated and isolating the tests. I think this makes it more explicit what is happening, but I could be convinced to leave the setup/populate functions as a fixture if people prefer that style.