Only index pages on creation
This commit is contained in:
parent
8cc32be33f
commit
56abc03f31
1 changed files with 6 additions and 1 deletions
|
@ -3,12 +3,15 @@ from django.db import connections
|
|||
from django.db.models.signals import post_save
|
||||
import warnings
|
||||
|
||||
|
||||
class CoreConfig(AppConfig):
|
||||
name = "yamdl_playground.core"
|
||||
|
||||
loaded = False
|
||||
|
||||
def ready(self):
|
||||
from .models import Page
|
||||
|
||||
if not self.loaded:
|
||||
connection = connections["default"]
|
||||
|
||||
|
@ -18,9 +21,11 @@ class CoreConfig(AppConfig):
|
|||
with connection.cursor() as cursor:
|
||||
cursor.execute("CREATE VIRTUAL TABLE search_index USING fts5(body);")
|
||||
|
||||
post_save.connect(self.post_save)
|
||||
post_save.connect(self.post_save, sender=Page)
|
||||
self.loaded = True
|
||||
|
||||
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)", [instance.content, instance.pk])
|
||||
|
|
Loading…
Reference in a new issue