1
Fork 0

Tweak SQLite config

This commit is contained in:
Jake Howard 2024-10-18 18:37:37 +01:00
parent 5c8caf37c0
commit 0747768fc6
Signed by: jake
GPG key ID: 57AFB45680EDD477
2 changed files with 24 additions and 6 deletions

2
.gitignore vendored
View file

@ -63,6 +63,8 @@ cover/
*.log *.log
local_settings.py local_settings.py
db.sqlite3 db.sqlite3
db.sqlite3-shm
db.sqlite3-wal
db.sqlite3-journal db.sqlite3-journal
# Flask stuff: # Flask stuff:

View file

@ -75,13 +75,26 @@ WSGI_APPLICATION = 'yamdl_playground.wsgi.application'
# Database # Database
# https://docs.djangoproject.com/en/5.0/ref/settings/#databases # https://docs.djangoproject.com/en/5.0/ref/settings/#databases
db_init_command = """ db_init_command = f"""
PRAGMA journal_mode=OFF; PRAGMA journal_mode=WAL;
PRAGMA synchronous=OFF; PRAGMA synchronous=NORMAL;
PRAGMA mmap_size = 134217728;
PRAGMA cache_size=4000;
PRAGMA temp_store=MEMORY; PRAGMA temp_store=MEMORY;
PRAGMA auto_vacuum=INCREMENTAL; 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 = { DATABASES = {
@ -89,13 +102,16 @@ DATABASES = {
'ENGINE': 'django.db.backends.sqlite3', 'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / "db.sqlite3", 'NAME': BASE_DIR / "db.sqlite3",
"CONN_MAX_AGE": 600, "CONN_MAX_AGE": 600,
"OPTIONS": {
"init_command": db_init_command
}
}, },
'yamdl': { 'yamdl': {
'ENGINE': 'django.db.backends.sqlite3', 'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'file:yamdl-db?mode=memory&cache=shared', 'NAME': 'file:yamdl-db?mode=memory&cache=shared',
"CONN_MAX_AGE": 600, "CONN_MAX_AGE": 600,
"OPTIONS": { "OPTIONS": {
"init_command": db_init_command "init_command": memory_db_init_command
} }
} }
} }