Gemini CLI
Final critical stability fixes: move to ephemeral disk, add auto-repair, and enable WAL mode
7890908 Download db/database.py from henry99a/avactress: direct link, hf CLI and curl.
- Browser
- Download file 1.02 kB
-
https://huggingface.co/spaces/henry99a/avactress/resolve/main/db/database.py
- Command line
-
hf download hf://spaces/henry99a/avactress/db/database.py
-
curl -L -o database.py https://huggingface.co/spaces/henry99a/avactress/resolve/main/db/database.py
1.02 kB
| import os | |
| from sqlalchemy import create_engine, event | |
| from sqlalchemy.orm import sessionmaker, scoped_session | |
| from .config import DATA_DIR | |
| DB_PATH = os.path.join(DATA_DIR, "sougouwiki.db") | |
| DATABASE_URL = f"sqlite:///{DB_PATH}" | |
| # Now that we run on local ephemeral disk (NOT tmpfs and NOT FUSE), | |
| # we can safely use WAL mode for high performance. | |
| engine = create_engine( | |
| DATABASE_URL, | |
| echo=False, | |
| connect_args={"check_same_thread": False, "timeout": 30} | |
| ) | |
| def set_sqlite_pragma(dbapi_connection, connection_record): | |
| cursor = dbapi_connection.cursor() | |
| # WAL mode is perfect for "Crawler writing, API reading" | |
| cursor.execute("PRAGMA journal_mode=WAL") | |
| cursor.execute("PRAGMA synchronous=NORMAL") | |
| cursor.execute("PRAGMA busy_timeout=30000") | |
| cursor.close() | |
| SessionLocal = scoped_session(sessionmaker(bind=engine)) | |
| def init_db(): | |
| from .models import Base | |
| Base.metadata.create_all(engine) | |
| def get_session(): | |
| return SessionLocal() | |