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
|
from .models import Page
|
||||||
|
|
||||||
if not self.loaded:
|
if not self.loaded:
|
||||||
connection = connections["default"]
|
connection = connections["yamdl"]
|
||||||
|
|
||||||
with warnings.catch_warnings():
|
with warnings.catch_warnings():
|
||||||
# Django doesn't like running DB queries during app initialization
|
# Django doesn't like running DB queries during app initialization
|
||||||
|
@ -34,8 +34,8 @@ class CoreConfig(AppConfig):
|
||||||
if not created:
|
if not created:
|
||||||
return
|
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])
|
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;")
|
cursor.execute("PRAGMA optimise;")
|
||||||
|
|
|
@ -7,7 +7,7 @@ from django.utils.safestring import mark_safe
|
||||||
|
|
||||||
|
|
||||||
def search(request):
|
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"])
|
cursor.execute("SELECT rowid FROM search_index WHERE search_index = %s;", ["content"])
|
||||||
row = cursor.fetchone()
|
row = cursor.fetchone()
|
||||||
pages = Page.objects.filter(id__in=row)
|
pages = Page.objects.filter(id__in=row)
|
||||||
|
|
|
@ -78,11 +78,8 @@ PRAGMA auto_vacuum=INCREMENTAL;
|
||||||
DATABASES = {
|
DATABASES = {
|
||||||
'default': {
|
'default': {
|
||||||
'ENGINE': 'django.db.backends.sqlite3',
|
'ENGINE': 'django.db.backends.sqlite3',
|
||||||
'NAME': 'file:default-db?mode=memory&cache=shared',
|
'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',
|
||||||
|
@ -102,8 +99,8 @@ YAMDL_LOADER = "yamdl_playground.core.utils.CustomYamdlLoader"
|
||||||
|
|
||||||
CACHES = {
|
CACHES = {
|
||||||
"default": {
|
"default": {
|
||||||
"BACKEND": "django.core.cache.backends.filebased.FileBasedCache",
|
"BACKEND": "django.core.cache.backends.db.DatabaseCache",
|
||||||
"LOCATION": BASE_DIR / "cache",
|
"LOCATION": "database_cache",
|
||||||
},
|
},
|
||||||
"mem": {
|
"mem": {
|
||||||
"BACKEND": "django.core.cache.backends.locmem.LocMemCache",
|
"BACKEND": "django.core.cache.backends.locmem.LocMemCache",
|
||||||
|
|
Loading…
Reference in a new issue