Skip to content
Snippets Groups Projects

refactor: use short-lived sessions when accessing the database

Closed Lars Kruse requested to merge lars-short-db-sessions into master
2 files
+ 100
37
Compare changes
  • Side-by-side
  • Inline
Files
2
  • Previously the database connection ("DB.session") was established during
    the startup of Aura Engine.
    This was causing conflicts in the threaded execution environment (#75).
    Now all sessions are acquired in a short-lived context:
    
      with DB.Session() as session:
          ...
    
    If database query performance is a real concern, then the session
    contexts could be moved to a higher level.
    
    Closes: #75
@@ -138,7 +138,8 @@ class FallbackManager:
if fallback_type != self.state.get("previous_fallback_type"):
timeslot = self.state["timeslot"]
if timeslot:
DB.session.merge(timeslot)
with DB.Session() as session:
session.merge(timeslot)
self.engine.event_dispatcher.on_fallback_active(timeslot, fallback_type)
Loading