From d43cfd22248953fa774bef699346f6152e28bc9e Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Sat, 24 Aug 2024 16:42:03 +0100 Subject: [PATCH] Optimise DB after insert --- yamdl_playground/core/apps.py | 4 ++++ yamdl_playground/settings.py | 1 + 2 files changed, 5 insertions(+) diff --git a/yamdl_playground/core/apps.py b/yamdl_playground/core/apps.py index 5ed3227..83dcd7e 100644 --- a/yamdl_playground/core/apps.py +++ b/yamdl_playground/core/apps.py @@ -33,5 +33,9 @@ class CoreConfig(AppConfig): def post_save(self, sender, instance, created, **kwargs): if not created: return + with connections["default"].cursor() as cursor: cursor.execute("INSERT INTO search_index(body, rowid) VALUES (%s, %s)", [strip_tags(instance.content), instance.pk]) + + with connections["default"].cursor() as cursor: + cursor.execute("PRAGMA optimise;") diff --git a/yamdl_playground/settings.py b/yamdl_playground/settings.py index f054a8d..fb95167 100644 --- a/yamdl_playground/settings.py +++ b/yamdl_playground/settings.py @@ -72,6 +72,7 @@ PRAGMA synchronous=OFF; PRAGMA mmap_size = 134217728; PRAGMA cache_size=4000; PRAGMA temp_store=MEMORY; +PRAGMA auto_vacuum=INCREMENTAL; """ DATABASES = {