Add DB cache
This commit is contained in:
parent
d43cfd2224
commit
2b2c905906
3 changed files with 7 additions and 10 deletions
|
@ -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;")
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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",
|
||||
|
|
Loading…
Reference in a new issue