Skip to content

Commit

Permalink
fix: 数据库并发修复
Browse files Browse the repository at this point in the history
  • Loading branch information
linyuan0213 committed Jul 12, 2024
1 parent fc763b5 commit 8ec393c
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions app/db/media_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import time

from cachetools import cached, TTLCache
from sqlalchemy import create_engine
from sqlalchemy import create_engine, text
from sqlalchemy.orm import sessionmaker, scoped_session
from sqlalchemy.pool import QueuePool

Expand All @@ -20,8 +20,14 @@
pool_pre_ping=True,
pool_size=100,
pool_recycle=60 * 10,
max_overflow=0
max_overflow=0,
connect_args={'timeout': 30}
)

# 启用 WAL 模式
with _Engine.connect() as conn:
conn.execute(text("PRAGMA journal_mode=WAL;"))

_Session = scoped_session(sessionmaker(bind=_Engine,
autoflush=True,
autocommit=False))
Expand Down

0 comments on commit 8ec393c

Please sign in to comment.