Permalink
Browse files

Added Gin Index on search_document

This dropped SQL time on /search/?q=python on my laptop down from
120ms to 55ms
  • Loading branch information...
simonw committed Oct 1, 2017
1 parent 5210b39 commit f3ffc1001b9d86e7557d96837d229a80ad3ea569
Showing with 32 additions and 0 deletions.
  1. +28 −0 blog/migrations/0006_gin_indexes.py
  2. +4 −0 blog/models.py
@@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.5 on 2017-10-01 01:48
from __future__ import unicode_literals
import django.contrib.postgres.indexes
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('blog', '0005_search_document'),
]
operations = [
migrations.AddIndex(
model_name='blogmark',
index=django.contrib.postgres.indexes.GinIndex(fields=[b'search_document'], name='blog_blogma_search__45eeb9_gin'),
),
migrations.AddIndex(
model_name='quotation',
index=django.contrib.postgres.indexes.GinIndex(fields=[b'search_document'], name='blog_quotat_search__aa2d47_gin'),
),
migrations.AddIndex(
model_name='entry',
index=django.contrib.postgres.indexes.GinIndex(fields=[b'search_document'], name='blog_entry_search__d62c3b_gin'),
),
]
View
@@ -5,6 +5,7 @@
from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.postgres.fields import JSONField
from django.contrib.postgres.search import SearchVectorField
from django.contrib.postgres.indexes import GinIndex
from django.utils.html import escape, strip_tags
import re
from xml.etree import ElementTree
@@ -98,6 +99,9 @@ def edit_url(self):
class Meta:
abstract = True
ordering = ('-created',)
indexes = [
GinIndex(fields=['search_document'])
]
class Entry(BaseModel):

0 comments on commit f3ffc10

Please sign in to comment.