From 527fce8a1dda8239a956ddc77b55d3d491732bd9 Mon Sep 17 00:00:00 2001 From: Ethanfel Date: Tue, 20 Jan 2026 13:11:48 +0100 Subject: [PATCH] Update engine.py --- engine.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/engine.py b/engine.py index 03ed9b8..eb90d85 100644 --- a/engine.py +++ b/engine.py @@ -18,11 +18,15 @@ class SorterEngine: @contextmanager def get_connection(): """Context manager for efficient DB connections with WAL mode.""" + # Ensure directory exists + db_dir = os.path.dirname(SorterEngine.DB_PATH) + if db_dir and not os.path.exists(db_dir): + os.makedirs(db_dir, exist_ok=True) + conn = sqlite3.connect(SorterEngine.DB_PATH, check_same_thread=False) conn.execute("PRAGMA journal_mode=WAL") # Write-Ahead Logging for speed conn.execute("PRAGMA synchronous=NORMAL") # Faster writes conn.execute("PRAGMA cache_size=2000") # ~2MB cache - conn.row_factory = sqlite3.Row # Efficient row access try: yield conn finally: