teamhide / fastapi-boilerplate

FastAPI boilerplate for real world production
1.12k stars 178 forks source link

Potential Performance Issue with Session Management in Repository Methods #40

Open vuxmai opened 2 months ago

vuxmai commented 2 months ago

I noticed that in the current implementation of the UserSQLAlchemyRepo, each repository method creates a new session using the session_factory() context manager. It can lead to potential performance issues when multiple repository methods are called sequentially within the same service layer function.

https://github.com/teamhide/fastapi-boilerplate/blob/ca3bb3fa5686cb031d6cd99d45b34fd7d2b12494/core/db/session.py#L51-L76

https://github.com/teamhide/fastapi-boilerplate/blob/ca3bb3fa5686cb031d6cd99d45b34fd7d2b12494/app/user/adapter/output/persistence/sqlalchemy/user.py#L29-L39