add max 5s writing delay for concurrent writers and flush WAL slower

This commit is contained in:
Nick Sweeting 2022-05-09 18:36:27 -07:00
parent c5ccb05d4a
commit 6e66863871

View file

@ -1169,10 +1169,17 @@ def setup_django(out_dir: Path=None, check_db=False, config: ConfigDict=CONFIG,
# Enable WAL mode in sqlite3 # Enable WAL mode in sqlite3
from django.db import connection from django.db import connection
with connection.cursor() as cursor: with connection.cursor() as cursor:
# Set Journal mode to WAL to allow for multiple writers
current_mode = cursor.execute("PRAGMA journal_mode") current_mode = cursor.execute("PRAGMA journal_mode")
if current_mode != 'wal': if current_mode != 'wal':
cursor.execute("PRAGMA journal_mode=wal;") cursor.execute("PRAGMA journal_mode=wal;")
# Set max blocking delay for concurrent writes and write sync mode
# https://litestream.io/tips/#busy-timeout
cursor.execute("PRAGMA busy_timeout = 5000;")
cursor.execute("PRAGMA synchronous = NORMAL;")
# Create cache table in DB if needed # Create cache table in DB if needed
try: try:
from django.core.cache import cache from django.core.cache import cache