Update engine.py
This commit is contained in:
@@ -18,11 +18,15 @@ class SorterEngine:
|
|||||||
@contextmanager
|
@contextmanager
|
||||||
def get_connection():
|
def get_connection():
|
||||||
"""Context manager for efficient DB connections with WAL mode."""
|
"""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 = sqlite3.connect(SorterEngine.DB_PATH, check_same_thread=False)
|
||||||
conn.execute("PRAGMA journal_mode=WAL") # Write-Ahead Logging for speed
|
conn.execute("PRAGMA journal_mode=WAL") # Write-Ahead Logging for speed
|
||||||
conn.execute("PRAGMA synchronous=NORMAL") # Faster writes
|
conn.execute("PRAGMA synchronous=NORMAL") # Faster writes
|
||||||
conn.execute("PRAGMA cache_size=2000") # ~2MB cache
|
conn.execute("PRAGMA cache_size=2000") # ~2MB cache
|
||||||
conn.row_factory = sqlite3.Row # Efficient row access
|
|
||||||
try:
|
try:
|
||||||
yield conn
|
yield conn
|
||||||
finally:
|
finally:
|
||||||
|
|||||||
Reference in New Issue
Block a user