1
Fork 0

Add DB cache

This commit is contained in:
Jake Howard 2024-10-05 14:02:40 +01:00
parent d43cfd2224
commit 2b2c905906
Signed by: jake
GPG key ID: 57AFB45680EDD477
3 changed files with 7 additions and 10 deletions

View file

@ -15,7 +15,7 @@ class CoreConfig(AppConfig):
from .models import Page
if not self.loaded:
connection = connections["default"]
connection = connections["yamdl"]
with warnings.catch_warnings():
# Django doesn't like running DB queries during app initialization
@ -34,8 +34,8 @@ class CoreConfig(AppConfig):
if not created:
return
with connections["default"].cursor() as cursor:
with connections["yamdl"].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:
with connections["yamdl"].cursor() as cursor:
cursor.execute("PRAGMA optimise;")

View file

@ -7,7 +7,7 @@ from django.utils.safestring import mark_safe
def search(request):
with connections["default"].cursor() as cursor:
with connections["yamdl"].cursor() as cursor:
cursor.execute("SELECT rowid FROM search_index WHERE search_index = %s;", ["content"])
row = cursor.fetchone()
pages = Page.objects.filter(id__in=row)

View file

@ -78,11 +78,8 @@ PRAGMA auto_vacuum=INCREMENTAL;
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'file:default-db?mode=memory&cache=shared',
'NAME': BASE_DIR / "db.sqlite3",
"CONN_MAX_AGE": 600,
"OPTIONS": {
"init_command": db_init_command
}
},
'yamdl': {
'ENGINE': 'django.db.backends.sqlite3',
@ -102,8 +99,8 @@ YAMDL_LOADER = "yamdl_playground.core.utils.CustomYamdlLoader"
CACHES = {
"default": {
"BACKEND": "django.core.cache.backends.filebased.FileBasedCache",
"LOCATION": BASE_DIR / "cache",
"BACKEND": "django.core.cache.backends.db.DatabaseCache",
"LOCATION": "database_cache",
},
"mem": {
"BACKEND": "django.core.cache.backends.locmem.LocMemCache",