From 0747768fc6826c55855646f2d19a3779ffa1e23d Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Fri, 18 Oct 2024 18:37:37 +0100 Subject: [PATCH] Tweak SQLite config --- .gitignore | 2 ++ yamdl_playground/settings.py | 28 ++++++++++++++++++++++------ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index cb3f739..55942ba 100644 --- a/.gitignore +++ b/.gitignore @@ -63,6 +63,8 @@ cover/ *.log local_settings.py db.sqlite3 +db.sqlite3-shm +db.sqlite3-wal db.sqlite3-journal # Flask stuff: diff --git a/yamdl_playground/settings.py b/yamdl_playground/settings.py index 1c1052e..4b32cf8 100644 --- a/yamdl_playground/settings.py +++ b/yamdl_playground/settings.py @@ -75,13 +75,26 @@ WSGI_APPLICATION = 'yamdl_playground.wsgi.application' # Database # https://docs.djangoproject.com/en/5.0/ref/settings/#databases -db_init_command = """ -PRAGMA journal_mode=OFF; -PRAGMA synchronous=OFF; -PRAGMA mmap_size = 134217728; -PRAGMA cache_size=4000; +db_init_command = f""" +PRAGMA journal_mode=WAL; +PRAGMA synchronous=NORMAL; PRAGMA temp_store=MEMORY; PRAGMA auto_vacuum=INCREMENTAL; +PRAGMA busy_timeout=10000; +PRAGMA threads={os.cpu_count()}; +PRAGMA secure_delete=OFF; +PRAGMA mmap_size=50000000; +PRAGMA cache_size=-262144; +""" + +memory_db_init_command = f""" +PRAGMA journal_mode=OFF; +PRAGMA synchronous=OFF; +PRAGMA temp_store=MEMORY; +PRAGMA auto_vacuum=INCREMENTAL; +PRAGMA busy_timeout=10000; +PRAGMA threads={os.cpu_count()}; +PRAGMA secure_delete=OFF; """ DATABASES = { @@ -89,13 +102,16 @@ DATABASES = { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': BASE_DIR / "db.sqlite3", "CONN_MAX_AGE": 600, + "OPTIONS": { + "init_command": db_init_command + } }, 'yamdl': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': 'file:yamdl-db?mode=memory&cache=shared', "CONN_MAX_AGE": 600, "OPTIONS": { - "init_command": db_init_command + "init_command": memory_db_init_command } } }