From b390c21227e1dfe55a20b5818ea7f2cef3bbfd92 Mon Sep 17 00:00:00 2001 From: Matt Westcott Date: Wed, 31 Aug 2016 17:36:35 +0100 Subject: [PATCH] Use a more efficient method to populate Rendition.filter_spec We now perform one bulk update for each filter record, rather than updating each Rendition record individually. --- wagtail/wagtailimages/utils.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/wagtail/wagtailimages/utils.py b/wagtail/wagtailimages/utils.py index 563571ad40..f1fe216af7 100644 --- a/wagtail/wagtailimages/utils.py +++ b/wagtail/wagtailimages/utils.py @@ -9,10 +9,12 @@ def get_fill_filter_spec_migrations(app_name, rendition_model_name): def fill_filter_spec_forward(apps, schema_editor): # Populate Rendition.filter_spec with the spec string of the corresponding Filter object Rendition = apps.get_model(app_name, rendition_model_name) + Filter = apps.get_model('wagtailimages', 'Filter') + db_alias = schema_editor.connection.alias - for rendition in Rendition.objects.using(db_alias).select_related('filter'): - rendition.filter_spec = rendition.filter.spec - rendition.save() + for flt in Filter.objects.using(db_alias): + renditions = Rendition.objects.using(db_alias).filter(filter=flt, filter_spec__isnull=True) + renditions.update(filter_spec=flt.spec) def fill_filter_spec_reverse(apps, schema_editor): # Populate the Rendition.filter