Speakr is a personal, self-hosted web application designed for transcribing audio recordings
Python
Add SQLite concurrency settings for multi-worker job queue
Murtaza Nasir7af7d25d2a0d
diff --git a/src/app.py b/src/app.pyindex 456a957a..7608ae60 100644--- a/src/app.py+++ b/src/app.py@@ -337,6 +337,16 @@ app = Flask(__name__,# Use environment variables or default paths for Docker compatibilityapp.config['SQLALCHEMY_DATABASE_URI'] = os.environ.get('SQLALCHEMY_DATABASE_URI', 'sqlite:////data/instance/transcriptions.db')app.config['UPLOAD_FOLDER'] = os.environ.get('UPLOAD_FOLDER', '/data/uploads')++# SQLite concurrency settings for multi-worker job queue+if 'sqlite' in app.config['SQLALCHEMY_DATABASE_URI']:+ app.config['SQLALCHEMY_ENGINE_OPTIONS'] = {+ 'connect_args': {+ 'timeout': 30, # Wait up to 30 seconds for locked database+ 'check_same_thread': False # Allow multi-threaded access+ },+ 'pool_pre_ping': True # Verify connections before use+ }# MAX_CONTENT_LENGTH will be set dynamically after database initialization# Set a secret key for session management and CSRF protectionapp.config['SECRET_KEY'] = os.environ.get('SECRET_KEY', 'default-dev-key-change-in-production')diff --git a/src/init_db.py b/src/init_db.pyindex a303749d..7c00397c 100644--- a/src/init_db.py+++ b/src/init_db.py@@ -29,9 +29,20 @@ def initialize_database(app):This function should be called within an app context."""db.create_all()-+# Check and add new columns if they don't existengine = db.engine++ # Enable WAL mode for SQLite (better concurrent write performance)+ if engine.name == 'sqlite':+ try:+ with engine.connect() as conn:+ conn.execute(text('PRAGMA journal_mode=WAL'))+ conn.commit()+ app.logger.info("SQLite WAL mode enabled for better concurrency")+ except Exception as e:+ app.logger.warning(f"Could not enable WAL mode: {e}")+try:# Add is_inbox column with default value of 1 (True)if add_column_if_not_exists(engine, 'recording', 'is_inbox', 'BOOLEAN DEFAULT 1'):