From 9bd04efd056b3bf563254260380baffbfb8f0373 Mon Sep 17 00:00:00 2001 From: Karl Hobley Date: Wed, 19 Aug 2015 12:15:40 +0100 Subject: [PATCH] Added index on AbstractImage.created_at Fixes #1598 Speeds up image index/chooser when many images exist in the site --- .../migrations/0007_auto_20150819_0614.py | 24 +++++++++++++++++++ .../migrations/0008_image_created_at_index.py | 19 +++++++++++++++ wagtail/wagtailimages/models.py | 2 +- 3 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 wagtail/tests/testapp/migrations/0007_auto_20150819_0614.py create mode 100644 wagtail/wagtailimages/migrations/0008_image_created_at_index.py diff --git a/wagtail/tests/testapp/migrations/0007_auto_20150819_0614.py b/wagtail/tests/testapp/migrations/0007_auto_20150819_0614.py new file mode 100644 index 0000000000..cdf17659a5 --- /dev/null +++ b/wagtail/tests/testapp/migrations/0007_auto_20150819_0614.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('tests', '0006_image_file_size'), + ] + + operations = [ + migrations.AlterField( + model_name='customimagewithadminformfields', + name='created_at', + field=models.DateTimeField(db_index=True, verbose_name='Created at', auto_now_add=True), + ), + migrations.AlterField( + model_name='customimagewithoutadminformfields', + name='created_at', + field=models.DateTimeField(db_index=True, verbose_name='Created at', auto_now_add=True), + ), + ] diff --git a/wagtail/wagtailimages/migrations/0008_image_created_at_index.py b/wagtail/wagtailimages/migrations/0008_image_created_at_index.py new file mode 100644 index 0000000000..23dda8c912 --- /dev/null +++ b/wagtail/wagtailimages/migrations/0008_image_created_at_index.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('wagtailimages', '0007_image_file_size'), + ] + + operations = [ + migrations.AlterField( + model_name='image', + name='created_at', + field=models.DateTimeField(db_index=True, verbose_name='Created at', auto_now_add=True), + ), + ] diff --git a/wagtail/wagtailimages/models.py b/wagtail/wagtailimages/models.py index 032a6cfff6..1439d5563a 100644 --- a/wagtail/wagtailimages/models.py +++ b/wagtail/wagtailimages/models.py @@ -63,7 +63,7 @@ class AbstractImage(models.Model, TagSearchable): file = models.ImageField(verbose_name=_('File'), upload_to=get_upload_to, width_field='width', height_field='height') width = models.IntegerField(verbose_name=_('Width'), editable=False) height = models.IntegerField(verbose_name=_('Height'), editable=False) - created_at = models.DateTimeField(verbose_name=_('Created at'), auto_now_add=True) + created_at = models.DateTimeField(verbose_name=_('Created at'), auto_now_add=True, db_index=True) uploaded_by_user = models.ForeignKey(settings.AUTH_USER_MODEL, verbose_name=_('Uploaded by user'), null=True, blank=True, editable=False) tags = TaggableManager(help_text=None, blank=True, verbose_name=_('Tags'))