Skip to content

Commit

Permalink
Move pooling to engines
Browse files Browse the repository at this point in the history
  • Loading branch information
funilrys committed Dec 19, 2023
1 parent 17545d5 commit c3d9aa8
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions PyFunceble/database/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,16 @@ def init_db_sessions(self) -> "DBSession":

if PyFunceble.sessions.DB_ENGINE is None:
PyFunceble.sessions.DB_ENGINE = sqlalchemy.create_engine(
self.credential.get_uri(), poolclass=sqlalchemy.pool.NullPool
self.credential.get_uri(),
poolclass=sqlalchemy.pool.NullPool,
pool_pre_ping=True,
)

PyFunceble.sessions.DB_FACTORY = sqlalchemy.orm.sessionmaker(
bind=PyFunceble.sessions.DB_ENGINE,
autoflush=True,
autocommit=False,
expire_on_commit=False,
pre_ping=True,
)

return self
Expand All @@ -177,15 +178,16 @@ def get_new_session(self) -> sqlalchemy.orm.sessionmaker:
"""

engine = sqlalchemy.create_engine(
self.credential.get_uri(), poolclass=sqlalchemy.pool.NullPool
self.credential.get_uri(),
poolclass=sqlalchemy.pool.NullPool,
pool_pre_ping=True,
)

return sqlalchemy.orm.sessionmaker(
bind=engine,
autoflush=True,
autocommit=False,
expire_on_commit=False,
pre_ping=True,
)

@execute_if_authorized(None)
Expand All @@ -195,16 +197,13 @@ def get_new_pool_session(self) -> sqlalchemy.orm.sessionmaker:
Create and return a new session.
"""

engine = sqlalchemy.create_engine(
self.credential.get_uri(),
)
engine = sqlalchemy.create_engine(self.credential.get_uri(), pool_pre_ping=True)

return sqlalchemy.orm.sessionmaker(
bind=engine,
autoflush=True,
autocommit=False,
expire_on_commit=False,
pre_ping=True,
)

def close(self) -> "DBSession":
Expand Down

0 comments on commit c3d9aa8

Please sign in to comment.