File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed
Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change 2828 case ,
2929 cast ,
3030 desc ,
31+ event as sqlalchemy_event ,
3132 func ,
3233 literal ,
3334 null ,
9293
9394
9495engine = create_db_engine ()
96+
97+
98+ @sqlalchemy_event .listens_for (engine , "connect" )
99+ def set_sqlite_pragma (dbapi_connection , connection_record ):
100+ if engine .dialect .name == "sqlite" :
101+ cursor = dbapi_connection .cursor ()
102+ cursor .execute ("PRAGMA journal_mode=WAL" )
103+ cursor .execute ("PRAGMA synchronous=NORMAL" )
104+ cursor .close ()
105+
106+
107+ @sqlalchemy_event .listens_for (engine , "checkout" )
108+ def checkout_listener (dbapi_connection , connection_record , connection_proxy ):
109+ # This prevents 'Idle in transaction' which often leads to pool exhaustion
110+ dbapi_connection .rollback ()
111+
95112SQLAlchemyInstrumentor ().instrument (enable_commenter = True , engine = engine )
96113
97114
@@ -2710,6 +2727,7 @@ def create_deduplication_event(
27102727 )
27112728 session .add (deduplication_event )
27122729 session .commit ()
2730+ session .refresh (deduplication_event )
27132731 logger .debug (
27142732 "Deduplication event added" ,
27152733 extra = {
You can’t perform that action at this time.
0 commit comments