From 2aa11fddfd5fd78a4a26818b97cf4b9d624880c6 Mon Sep 17 00:00:00 2001 From: Oscar Cortez Date: Thu, 21 May 2020 18:45:09 -0600 Subject: [PATCH] Remove search vector from Article model --- ...from.py => 0003_article_inherited_from.py} | 2 +- .../migrations/0003_article_search_vector.py | 19 ------------- .../migrations/0004_auto_20200521_0950.py | 28 +++++++++++++++++++ src/wiki/models/article.py | 21 -------------- 4 files changed, 29 insertions(+), 41 deletions(-) rename src/wiki/migrations/{0004_article_inherited_from.py => 0003_article_inherited_from.py} (91%) delete mode 100644 src/wiki/migrations/0003_article_search_vector.py create mode 100644 src/wiki/migrations/0004_auto_20200521_0950.py diff --git a/src/wiki/migrations/0004_article_inherited_from.py b/src/wiki/migrations/0003_article_inherited_from.py similarity index 91% rename from src/wiki/migrations/0004_article_inherited_from.py rename to src/wiki/migrations/0003_article_inherited_from.py index 2fe97260..1bab31af 100644 --- a/src/wiki/migrations/0004_article_inherited_from.py +++ b/src/wiki/migrations/0003_article_inherited_from.py @@ -7,7 +7,7 @@ import django.db.models.deletion class Migration(migrations.Migration): dependencies = [ - ('wiki', '0003_article_search_vector'), + ('wiki', '0002_auto_20191213_0603'), ] operations = [ diff --git a/src/wiki/migrations/0003_article_search_vector.py b/src/wiki/migrations/0003_article_search_vector.py deleted file mode 100644 index cf87268c..00000000 --- a/src/wiki/migrations/0003_article_search_vector.py +++ /dev/null @@ -1,19 +0,0 @@ -# Generated by Django 2.2.10 on 2020-04-30 20:47 - -import django.contrib.postgres.search -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ('wiki', '0002_auto_20191213_0603'), - ] - - operations = [ - migrations.AddField( - model_name='article', - name='search_vector', - field=django.contrib.postgres.search.SearchVectorField(null=True), - ), - ] diff --git a/src/wiki/migrations/0004_auto_20200521_0950.py b/src/wiki/migrations/0004_auto_20200521_0950.py new file mode 100644 index 00000000..4d37b136 --- /dev/null +++ b/src/wiki/migrations/0004_auto_20200521_0950.py @@ -0,0 +1,28 @@ +# Generated by Django 2.2.12 on 2020-05-21 16:50 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('wiki', '0003_article_inherited_from'), + ] + + operations = [ + migrations.AlterField( + model_name='urlpath', + name='level', + field=models.PositiveIntegerField(db_index=True, editable=False), + ), + migrations.AlterField( + model_name='urlpath', + name='lft', + field=models.PositiveIntegerField(db_index=True, editable=False), + ), + migrations.AlterField( + model_name='urlpath', + name='rght', + field=models.PositiveIntegerField(db_index=True, editable=False), + ), + ] diff --git a/src/wiki/models/article.py b/src/wiki/models/article.py index 8e57d3cb..7da7d690 100644 --- a/src/wiki/models/article.py +++ b/src/wiki/models/article.py @@ -1,7 +1,6 @@ from django.conf import settings as django_settings from django.contrib.contenttypes.fields import GenericForeignKey from django.contrib.contenttypes.models import ContentType -from django.contrib.postgres.search import SearchVector, SearchVectorField from django.core.cache import cache from django.db import models, transaction from django.db.models import OuterRef, Subquery @@ -75,8 +74,6 @@ class Article(models.Model): 'grinch.Organization', related_name='articles', null=True, blank=True, on_delete=models.CASCADE) - search_vector = SearchVectorField(null=True) - inherited_from = models.ForeignKey( 'self', related_name='inherit_children', null=True, blank=True, on_delete=models.SET_NULL, @@ -108,24 +105,6 @@ class Article(models.Model): for obj in self.articleforobject_set.filter(is_mptt=True): yield from obj.content_object.get_descendants() - @transaction.atomic - def update_search_vector(self): - Article.objects.annotate( - wiki_title=Subquery( - Article.objects.filter(id=OuterRef('id')).values( - 'current_revision__title' - ) - ), - wiki_body=Subquery( - Article.objects.filter(id=OuterRef('id')).values( - 'current_revision__content' - ) - ), - ).filter(id=self.id).update( - search_vector=SearchVector('wiki_title', weight='A') - + SearchVector('wiki_body', weight='B') - ) - def get_children(self, max_num=None, user_can_read=None, **kwargs): """NB! This generator is expensive, so use it with care!!""" cnt = 0 -- 2.45.2